Re: OOP php user system



703designs wrote:
On Nov 10, 6:02 am, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:
703designs wrote:
On Nov 9, 11:28 pm, "Jessica Griego" <j...@xxxxxxxxxxx> wrote:
"703designs" <thomasmal...@xxxxxxxxx> wrote in message
news:87a79792-c2b5-477a-8376-774d3951453f@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Nov 9, 10:46 pm, 703designs <thomasmal...@xxxxxxxxx> wrote:
On Nov 9, 10:37 pm, "Jessica Griego" <j...@xxxxxxxxxxx> wrote:
"Yorian" <yorianbenja...@xxxxxxxxxxx> wrote in message
news:8b1c4864-385d-45fa-bb75-3b9d2b736532@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hey,
Although 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
putting 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
actually do things the way they should be done to make a nice
maintainable module. Which in fact means that I'm trying to stick to
some rules: Don't repeat yourself, seperation of concerns,
encapsulation, etc.
I've created (not finished just started it) a user system, this
according 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
direction?
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
private function and use the 'static' keyword for the other
functions/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
singleton.
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
$userInstance->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
performance 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
languages' 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...@xxxxxxxxxxxxx
==================

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

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.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: OOP php user system
    ... never actually programmed proper OO code yet. ... Python's my first language and this sort of thing works very ... design, even in Python. ... Jerry, Jerry, Jerry! ...
    (comp.lang.php)
  • Re: OOP php user system
    ... never actually programmed proper OO code yet. ... Python's my first language and this sort of thing works ... design, even in Python. ... Jerry, Jerry, Jerry! ...
    (comp.lang.php)
  • Re: OOP php user system
    ... never actually programmed proper OO code yet. ... what language the comments are in, ... those singletons the constructor args. ... design, even in Python. ...
    (comp.lang.php)
  • Re: OOP php user system
    ... never actually programmed proper OO code yet. ... those singletons the constructor args. ... to rig the jury to obtain the get/set functionality that is supplied by ... Part of good OO design is to keep separate things separate - that includes attributes. ...
    (comp.lang.php)
  • Re: initializing mutable class attributes
    ... I need to understand the 'WHY' behind a design ... satisfied with an explanation of "that's the Python way and you just have to ... the design of a language can make a very good language. ... default constructor and a non-default one at the same time. ...
    (comp.lang.python)