[Typo3-dev] singletons instead of pre-loaded objects
Karsten Dambekalns
k.dambekalns at fishfarm.de
Thu Aug 12 11:26:12 CEST 2004
Hi Leendert,
thanks for the answer.
On 2004-08-11, Leendert Brouwer [Netcreators] <leendert at netcreators.nl> wrote:
> Then you just output some data from a database ;) It is a misconception that
> you _have_ to use patterns to use proper OO. Patterns should be applied
...
> Just to scratch the surface, know that in OO, an object actually has to
> represent an object (and that is less of a "duh"-moment than it might seem
> sometimes). The object represented should be as complete as is needed for
Well, okay. Objects are not the real problem, I think. And I do grasp
all the nice examples out there about cars having parts and
methods. But, honestly, what gives me trouble are mostly those two
things (maybe, as soon as I 'got' those, it'll all fall in to places):
1. Fetching a list of items from a DB
Say we have a list of contacts to fetch. Each contact is an object
(with attributes like name, address, ... and getter/setter methods for
those). So, I could just 'select * from' and iterate over the result
set. Where do I place this in the OO world? Do I create another object
like ContactList that has methods like fetchAll() or searchFor()?
2. Saving items to the DB
I instanciate an object. Fine, now set some attributes, call some
methods. Now I want this to be stored in the database. It seems as if
calling a method saveToDB() is a bit awkward? Or is it a Good
Thing[tm]? Would it be better if objects that are supposed to be
persistent would store themselves automatically on destruction? And
what about deleting? Would I call deleteFromDB() on an instance?
And there's the question on how exact one follows the model one has
come up with. Say we have users and administrators - naturally two
classes, the administrator just having more rights. In 'real life',
I'd never create two classes, but just add a flag isadmin to the user
class and add an isAdmin() method. Is this good, bad or nonsense?
Sorry for the long post (and the maybe silly questions :).
Karsten
PS: Seems as if the refactoring article you mentioned isn't available
online... :(
More information about the TYPO3-dev
mailing list