[Typo3-dev] Library manager instead of globals
dan frost
dan at danfrost.co.uk
Tue Mar 16 13:08:16 CET 2004
Martin T. Kutschker wrote:
> dan frost wrote:
>
>> Last night I built a library manager to cope with a load of the
>> classes I'm using.
>
>
> Generally speaking a good idea.
>
> I know I'm nitpicking but I don't like the nomenclatura.
>
> registerClass() and createInstance() or getInstance() are IMHO easier
> understood than these library entry stuff.
>
Yes - i'm always rubbish at naming.
> You might dislike class, because it might be confused wit PHP classes.
> But a library is a collection of functions and classes, so confusion
> waits here as well.
In this instance a library is a collection of classes - so i think it's
the same
>
> BTW, you're aware that your constructors won't have any arguments? Not
> that Typo3 uses constructors...
>
I have to solve that... The constructor could come after. E.g.:
$myOb = library::createInstance('someclass');
$myOb->init(var.var....etc)
Not sure - i'm going to look at some good patterns.
>> This means:
>> 1. you can have a default "object" or register errors when
>> non-existent objects are created
>> 2. you can have lots of classes supplying the same "class name"
>> (libraryKey) - so for extensions you can have:
>
>
> You don't really elaborate on how the loader should determine what class
> should be instantiated. "user permissions" etc is a bit vague.
>
The loader could use anything. The library manager just gives the
ability to add things and get things. Child-classes of the library
manager could add specific rules and so on.
> Idea: a "class" could mark itself as a singleton. This way the loader
> can pass a reference to an existing object. Makes the static class
> functions go away.
>
Yea - also you could use Flyweight to minimize overheads caused my
unessary objects.
Bascially, the library manager can manage the creation of all objects.
Child classes could add specfic checking abilities (e.g singleton,
replacement classes, flyweight). The whole thing gives a much neater way
of managing the many classes.
The advantage of this over the "globals" is that this method wraps the
objects in the system in a protective logic layer.
dan
More information about the TYPO3-dev
mailing list