Re: OOP php user system
- From: "Jessica Griego" <jess@xxxxxxxxxxx>
- Date: Sun, 9 Nov 2008 23:10:51 -0600
"703designs" <thomasmallen@xxxxxxxxx> wrote in message
news:b0914478-f249-4d4a-9e10-586c7092ac07@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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.
===========
I understand, however Python's get/set is not php's get/set. I was *very*
excited when I saw the __get/set in php for the first time! That is, until I
saw that it was NOT what I was used to either. Maybe they'll put actual
get/set constructs in another version down the road...because I have
relatively no use for what php is trying to get out of the current
implementation.
Have a good one.
.
- References:
- OOP php user system
- From: Yorian
- Re: OOP php user system
- From: Jessica Griego
- Re: OOP php user system
- From: Jessica Griego
- OOP php user system
- Prev by Date: Re: OOP php user system
- Next by Date: newbie: website's root directory
- Previous by thread: Re: OOP php user system
- Next by thread: Re: OOP php user system
- Index(es):
Relevant Pages
|