|
Posted by Simon Dean on 08/16/06 09:50
Hi,
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 :)
DataFlex is mainly procedural. You can do a certain amount of OOP
programing, but the company I worked for refused. However it really was
such a kick I remember, being able to develop these little plug in
modules and tools that can be just be used within a program, and they
didn't care about the outside environment etc.
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.
So Im pushing along with Classes in re-writing one of my websites,
http://www.celebrityresearcher.co.uk
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.
The reset, will check the login against the email, get a new password
from GeneratePassword, send it off using MailPassword and voila.
But then I had the validate function, and I was wondering whether
Session creation should be called from the Validate function, passing
the Session object back, or just have the calling program Create a
Session Object.
Of course the flipside of the coin, I create a new Session Object, ask
it validate the password, by getting it to create a new Password object,
etc...
The answer Im guessing is no. The Password class should not be reliant
upon the Session class and vice versa, since I might not want to do
anything with Sessions in all instances. The two should be kept distinct
and the calling program should handle all function calls itself. Right?
So then I find a situation say with Opening a Page, where dependant upon
whether Im looking at an item, or say, whether the user is logged in or
not (ie we have a session object set), we want to do something
different, So I was working on:
<?
Class Celebrity {
var $DName;
var $DAge;
function Celebrity() {
}
}
Class Page {
var $Celebrity;
function Page() {
}
function Open() {
if(isset($this->Celebrity)) {
echo "Celebrity is set as " . $this->Celebrity->DName;
}
else {
echo "No celebrity is set";
}
}
}
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.
Or perhaps it IS better, just to work out what information I actually
need, and just pass that across on function parameters?
Which way is right?
Thanks
Simon
Navigation:
[Reply to this message]
|