Re: OOP php user system
703designs wrote:
Which does not mean it's a good design. If you had a good design, you
don't need the __get() method.
That is, if _get() worked the way YOU wish it did.
You should read some of the GOOD OOAD books. Ones by long recognized
names like Booch, Rumbaugh, and similar.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attgl obal.net
=============== ===
703designs wrote:
On Nov 10, 10:17 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>
If my application design is such that getting and setting will
probably be required in the future, I can avoid massive refactoring by
mapping assignment to __set and retrieval to __get. That way, in the
early stages I can use:
>
echo $this->name;
>
and even if it's used site-wide, I can instantly map all of these
references to $this->getName() if I use __get properly.
>
>703designs wrote:
>Then if each attribute has it's own get/set pair (as in good OO design),
>there is no need for the __get/__set methods.
>>
>That's why you won't find them in good OO languages such as SmallTalk,
>Java and even C++.
>>
>--
>============== ====
>Remove the "x" from my email address
>Jerry Stuckle
>JDS Computer Training Corp.
>jstuck...@attg lobal.net
>============== ====
>>On Nov 10, 6:02 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>>>703designs wrote:
>>>>On Nov 9, 11:28 pm, "Jessica Griego" <j...@example.c omwrote:
>>>>>"703design s" <thomasmal...@g mail.comwrote in message
>>>>>news:87a79 792-c2b5-477a-8376-774d3951453f@a2 6g2000prf.googl egroups.com...
>>>>>On Nov 9, 10:46 pm, 703designs <thomasmal...@g mail.comwrote:
>>>>>>On Nov 9, 10:37 pm, "Jessica Griego" <j...@example.c omwrote:
>>>>>>>"Yoria n" <yorianbenja... @hotmail.comwro te in message
>>>>>>>news:8b1 c4864-385d-45fa-bb75-3b9d2b736532@t3 9g2000prh.googl egroups.com...
>>>>>>>>Hey,
>>>>>>>>Althoug h I've been using classes and object for quite a while now I've
>>>>>>>>never actually programmed proper OO code yet. It ofcourse depends on
>>>>>>>>what you call proper OO code. I have been seperating parts of the
>>>>>>>>website . Like a user class, guestbook class, etc. But I've been
>>>>>>>>putti ng all the code in one single class instead of of spreiding it.
>>>>>>>>Since a short while I've been reading up on OOP and now I am trying to
>>>>>>>>actuall y do things the way they should be done to make a nice
>>>>>>>>maintai nable module. Which in fact means that I'm trying to stick to
>>>>>>>>some rules: Don't repeat yourself, seperation of concerns,
>>>>>>>>encapsu lation, etc.
>>>>>>>>I've created (not finished just started it) a user system, this
>>>>>>>>accordi ng to the mvc pattern. The names for the classes aren't perfect
>>>>>>>>(user should actually be named userController, and userData should be
>>>>>>>>named user, etc.).
>>>>>>>>Could any of you guys have a look and see if I'm going in the right
>>>>>>>>directi on?
>>>>>>>>The few classes (put in a single file for the sake of easy reading)
>>>>>>>>can be found here:http://web-develop.nl/user_oop.phps
>>>>>>>>Hope you guys can give me some useful comments.
>>>>>>>The thing I like most, Yorian, is that it is well formatted! I don't
>>>>>>>know
>>>>>>>what language the comments are in, however I do recognize 'singleton'.
>>>>>>>For
>>>>>>>the classes that are singletons, you need to make the __constructor a
>>>>>>>privat e function and use the 'static' keyword for the other
>>>>>>>function s/variables in the class. You'd necissarily need a way to supply
>>>>>>>those singletons the constructor args. You can either let the caller set
>>>>>>>the
>>>>>>>values via 'setters' and/or create a static function, like 'initialize',
>>>>>>>that essentially carries out the responsibility of __construct. You
>>>>>>>should
>>>>>>>also think about defining __clone, __copy, etc. specifically as private
>>>>>>>so
>>>>>>>that you are guaranteed not to have more than one instance of the
>>>>>>>singleto n.
>>>>>>>Again, I like the code most because I can readily tell what it is
>>>>>>>doing... because it is well formatted. Above all, that will save time,
>>>>>>>money,
>>>>>>>and frustration when you need to add to it or modify it in some way in
>>>>>>>the
>>>>>>>future .
>>>>>>>Cheers
>>>>>>Instead of using all of those getAttribute methods, you could use a
>>>>>>generic __get method that returns the attribute.
>>>>>>Thomas
>>>>>Ah, my fault, it's late. I meant that you can use __get to point to
>>>>>those methods automatically using call_user_func. So that
>>>>>$userInsta nce->last_name would call that method.
>>>>>========
>>>>>IMO, that's very bad advice. __get and __set only get executed when a caller
>>>>>tries to access an *undefined* interface. You're abusing the actual intent
>>>>>of __get/set. It makes it terribly hard to debug and manage. It doesn't
>>>>>allow you to strongly type the input(s) or output(s). It's also a
>>>>>performanc e hit. Further, you should notice tools like php documentor and
>>>>>any screen dump of the object would not accurately show any validation for
>>>>>the properties being set. I'd think about always being specific and not try
>>>>>to rig the jury to obtain the get/set functionality that is supplied by
>>>>>other oop languages. __get and __set are NOT php's version of other
>>>>>language s' get/set construct.
>>>>Sorry, Python's my first language and this sort of thing works very
>>>>cleanly there. I'll keep these drawbacks in mind: I guess that __get's
>>>>not quite ready for primetime.
>>>>Thomas
>>>In addition, the generic __get and __set methods are contrary to good OO
>>>design, even in Python.
>>>Part of good OO design is to keep separate things separate - that
>>>includes attributes. Independent getter and setter methods, while a
>>>paid to code, do this quite nicely. They also allow for easier
>>>validation/massage of the data. A single __get/__set method pair does
>>>not do this.
>>>--
>>>============ ======
>>>Remove the "x" from my email address
>>>Jerry Stuckle
>>>JDS Computer Training Corp.
>>>jstuck...@at tglobal.net
>>>============ ======
>>I never said that a single get/set pair should do that. Another part
>>of good OO design is to not reference object attributes directly, but
>>rather to always have getter and setter methods.
>>Thomas
>>>703designs wrote:
>>>>On Nov 9, 11:28 pm, "Jessica Griego" <j...@example.c omwrote:
>>>>>"703design s" <thomasmal...@g mail.comwrote in message
>>>>>news:87a79 792-c2b5-477a-8376-774d3951453f@a2 6g2000prf.googl egroups.com...
>>>>>On Nov 9, 10:46 pm, 703designs <thomasmal...@g mail.comwrote:
>>>>>>On Nov 9, 10:37 pm, "Jessica Griego" <j...@example.c omwrote:
>>>>>>>"Yoria n" <yorianbenja... @hotmail.comwro te in message
>>>>>>>news:8b1 c4864-385d-45fa-bb75-3b9d2b736532@t3 9g2000prh.googl egroups.com...
>>>>>>>>Hey,
>>>>>>>>Althoug h I've been using classes and object for quite a while now I've
>>>>>>>>never actually programmed proper OO code yet. It ofcourse depends on
>>>>>>>>what you call proper OO code. I have been seperating parts of the
>>>>>>>>website . Like a user class, guestbook class, etc. But I've been
>>>>>>>>putti ng all the code in one single class instead of of spreiding it.
>>>>>>>>Since a short while I've been reading up on OOP and now I am trying to
>>>>>>>>actuall y do things the way they should be done to make a nice
>>>>>>>>maintai nable module. Which in fact means that I'm trying to stick to
>>>>>>>>some rules: Don't repeat yourself, seperation of concerns,
>>>>>>>>encapsu lation, etc.
>>>>>>>>I've created (not finished just started it) a user system, this
>>>>>>>>accordi ng to the mvc pattern. The names for the classes aren't perfect
>>>>>>>>(user should actually be named userController, and userData should be
>>>>>>>>named user, etc.).
>>>>>>>>Could any of you guys have a look and see if I'm going in the right
>>>>>>>>directi on?
>>>>>>>>The few classes (put in a single file for the sake of easy reading)
>>>>>>>>can be found here:http://web-develop.nl/user_oop.phps
>>>>>>>>Hope you guys can give me some useful comments.
>>>>>>>The thing I like most, Yorian, is that it is well formatted! I don't
>>>>>>>know
>>>>>>>what language the comments are in, however I do recognize 'singleton'.
>>>>>>>For
>>>>>>>the classes that are singletons, you need to make the __constructor a
>>>>>>>privat e function and use the 'static' keyword for the other
>>>>>>>function s/variables in the class. You'd necissarily need a way to supply
>>>>>>>those singletons the constructor args. You can either let the caller set
>>>>>>>the
>>>>>>>values via 'setters' and/or create a static function, like 'initialize',
>>>>>>>that essentially carries out the responsibility of __construct. You
>>>>>>>should
>>>>>>>also think about defining __clone, __copy, etc. specifically as private
>>>>>>>so
>>>>>>>that you are guaranteed not to have more than one instance of the
>>>>>>>singleto n.
>>>>>>>Again, I like the code most because I can readily tell what it is
>>>>>>>doing... because it is well formatted. Above all, that will save time,
>>>>>>>money,
>>>>>>>and frustration when you need to add to it or modify it in some way in
>>>>>>>the
>>>>>>>future .
>>>>>>>Cheers
>>>>>>Instead of using all of those getAttribute methods, you could use a
>>>>>>generic __get method that returns the attribute.
>>>>>>Thomas
>>>>>Ah, my fault, it's late. I meant that you can use __get to point to
>>>>>those methods automatically using call_user_func. So that
>>>>>$userInsta nce->last_name would call that method.
>>>>>========
>>>>>IMO, that's very bad advice. __get and __set only get executed when a caller
>>>>>tries to access an *undefined* interface. You're abusing the actual intent
>>>>>of __get/set. It makes it terribly hard to debug and manage. It doesn't
>>>>>allow you to strongly type the input(s) or output(s). It's also a
>>>>>performanc e hit. Further, you should notice tools like php documentor and
>>>>>any screen dump of the object would not accurately show any validation for
>>>>>the properties being set. I'd think about always being specific and not try
>>>>>to rig the jury to obtain the get/set functionality that is supplied by
>>>>>other oop languages. __get and __set are NOT php's version of other
>>>>>language s' get/set construct.
>>>>Sorry, Python's my first language and this sort of thing works very
>>>>cleanly there. I'll keep these drawbacks in mind: I guess that __get's
>>>>not quite ready for primetime.
>>>>Thomas
>>>In addition, the generic __get and __set methods are contrary to good OO
>>>design, even in Python.
>>>Part of good OO design is to keep separate things separate - that
>>>includes attributes. Independent getter and setter methods, while a
>>>paid to code, do this quite nicely. They also allow for easier
>>>validation/massage of the data. A single __get/__set method pair does
>>>not do this.
>>>--
>>>============ ======
>>>Remove the "x" from my email address
>>>Jerry Stuckle
>>>JDS Computer Training Corp.
>>>jstuck...@at tglobal.net
>>>============ ======
>>I never said that a single get/set pair should do that. Another part
>>of good OO design is to not reference object attributes directly, but
>>rather to always have getter and setter methods.
>>Thomas
>there is no need for the __get/__set methods.
>>
>That's why you won't find them in good OO languages such as SmallTalk,
>Java and even C++.
>>
>--
>============== ====
>Remove the "x" from my email address
>Jerry Stuckle
>JDS Computer Training Corp.
>jstuck...@attg lobal.net
>============== ====
If my application design is such that getting and setting will
probably be required in the future, I can avoid massive refactoring by
mapping assignment to __set and retrieval to __get. That way, in the
early stages I can use:
>
echo $this->name;
>
and even if it's used site-wide, I can instantly map all of these
references to $this->getName() if I use __get properly.
>
don't need the __get() method.
That is, if __get worked the way we wish it did :^)
>
>
You should check out Manning Press' "PHP in Action." It has some top-
notch writing on this subject. Their recommendation is the same as
Jessica's (that __get's not designed/implemented appropriately for
this use quite yet).
>
Thanks,
Thomas
notch writing on this subject. Their recommendation is the same as
Jessica's (that __get's not designed/implemented appropriately for
this use quite yet).
>
Thanks,
Thomas
names like Booch, Rumbaugh, and similar.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attgl obal.net
=============== ===
Comment