|
Posted by Dikkie Dik on 08/16/06 19:34
> Thanks for everyones advice so far. Really useful, and have given me
> some things to think about. I come from a background of VB and DataFlex
> programming. I guess VB is abhorrent, in that you click a button, the
> button has to do something else with another control and everything
> breaks out to the outside :)
Why? Just because you can type some code in an event handler, that does
not mean that your entire program must reside there. You can do a lot of
object-orientation in VB. It is not VB's fault that so few programmers do.
> I used to be such a good programmer, now Im working for a company who
> writes classes that represents database tables rather than sort of,
> abstract concepts. So we might have a Persons class that gets passed a
> SQL String and serves as a Collection of Person classes. And each field
> is a property of the database table. Seems a bit archaic to me and more
> complicated than just referring to the database.
Often, I do this as well. My table wrappers abstract the main entities
in the storage. These main entities are usually also defined in my
object-oriented model, so a mapping is not that bad.
The table wrappers's responsibility is the (for me) handling the storage
and the storage strategy, without bothering the rest of the program.
This strategy can be "greedy" (load as much as you think you need once,
in one batch) or "lazy" (on demand) or even a mixture of the two. I
wrote more on that in:
http://www.w-p.dds.nl/article/wtrframe.htm
> I've created a Password class that can do:
>
> function Validate($pLogin, $pPassword) {
> function MailPassword($pLogin, $pPassword, $pEmail) {
> function GeneratePassword() {
> function ResetPassword($pLogin, $pEmail) {
>
> And only has two variables, an Error code, and an Error string.
I would think more like an organization. Some client wants to enter your
website, but is only allowed to do so if the door-keeper has verified
your identity. The door-keeper will usually not generate the password
himself, and it is the postman that will deliver it.
So there are tree objects here:
- DoorKeeper
- UserAccount or PasswordManager
- Mailer (or TemplateMailer)
The DoorKeeper needs a username and a password and may return a
UserAccount. Now, Doorkeeper could also be constructed with a session
value, a cookie value or whatever. It is the DoorKeeper's responsibility
to check valid identities. Just like in real life, where more than one
document may be a valid identification.
The UserAccount holds the user data (is a record wrapper initially), but
can accept a request to reset a password. Upon password change, it
(perhaps indirectly) informs the password mailer.
This password mailer can also be activated by the "forgot password code"
The password mailer uses the general mailer to send the notification.
During unit testing, you can replace the general mailer with a test
double, so you can check that the mail _would_ have been sent, without
actually spamming someone.
.... <snip> ...
> This way, my Page class can get all the information it needs from the
> Celebrity object while generating a page, and it's easy to expand upon.
> Though it is reliant upon another class? I did the same thing with a
> Session object, so I could tell it to construct a different menu, and
> even present the name of the user from the session object for example.
That is up to you. Play with it and see where it gets you. You can
always reverse the dependencies: You could instruct a celebrity to
"render" itself of a page. In this case, The celebrity object would get
a render method, with a page as parameter. If you find the page too
specific as parameter, you can define an abstract super class (or
interface) "renderer", of which the page inherits.
Compare this with your MP3 player. It contains music, but it accepts an
audio plug to send the signal to. This audio plug is an interface.
Anything that implements that interface will do: headphones, little
speakers, the soundcard of your computer, etc. All these devices have an
audio input plug, and therefore implement the "AudioPlayer" interface.
Good luck!
Navigation:
[Reply to this message]
|