|
Posted by Manuel Lemos on 09/19/05 20:58
Hello,
on 09/19/2005 02:33 PM Chris W. Parker said the following:
> Let's take for example a class called 'Customer' that (obviously)
> manipulates customers in the database. Here is a very basic Customer
> class. (Data validation and the like are left out for brevity.)
This is a basic object persistence problem.
> (Unless I've already got some major design flaws I think we should be
> good to go.)
>
> Where I get tripped up is when I realize I'll need to at some point
> get more than one customer at a time and thus I want to add a method
> called 'get_customers()'.
Yes, there is a problem. You are trying to retrieve objects into memory
before they exist. It makes more sense that you retrieve objects using a
factory class.
That is the approach of Metastorage. You may want to take a looka at
Metastorage before you reinvent the wheel.
Metastorage is an persistent object class generator tool that lets you
design your persistent object classes using a simple XML format that
describes the classes, variables, validation rules, relationships and
any functions that you may need to manipulate your objects.
Besides the persistent object classes, it also generates a factory class
that takes care creating new objects from scratch or retrieve them from
the database. The factory class makes sure that each object does not
exist more than once in memory.
When you want to retrieve a collection of objects of the same class. You
just add a function to the factory class to retrieve such objects,
instead of calling the actual class of the objects your are retrieving.
You can also retrieve a collection of objects related to an object right
from its class, for instance retrieving children objects of given parent
object. In that case you would add a function to the parent object
class, despite internally Metastorage implements that using calls to the
factory class, which is itself a singleton.
Anyway, if you want to know more about Metastorage, you may find more
information here:
http://www.meta-language.net/metastorage.html
There is a tutorial here:
http://www.meta-language.net/metastorage-tutorial.html
Some screenshots of the Web interface:
http://www.meta-language.net/screenshots.html
--
Regards,
Manuel Lemos
PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/
Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Navigation:
[Reply to this message]
|