Re: Object-Oriented database model using relational database -
10-16-2004
, 08:30 PM
Dear Carl and Friedrich,
Actually, I agree with you that PHP is not the best object-oriented
choice, but what I am looking for is some kind of API or library for
PHP that can support object-oriented hierarchy for objects stored among
relational database. It is not important, at least for me, to make my
application built on object-oriented basis. The application I am
working on, basically, manipulates tables (browsing, editing,
searching, filtering and reporting) that stores information about
different items that have some common properties and many other
specific properties to each class of these items; there is some kind of
inheritance in the information related to these kinds of items. The
problem is that new items can be introduced in the future, that is in
addition to the large number of item classes are currently supported.
My imagination about such system, for tables for this system could have
this structure:
"CLASSES" table:
1. id (primary key)
2. name (class name)
3. ancestor (key of the ancestor class)
"OBJECT" table (stores the object class attributes for all objects
which are driven form this class Object):
1. id (primary key)
2. class (reference to the class record, in the classes table)
3. references (the number of references to the object represented by
this record)
"COLLECTIONITEM" table (stores the attributes of CollectionItem
objects, references to objects; driven from the class Object)
1. id (primary key)
2. collection (reference to record in the COLLECTION table, the
Collection that this object is member of)
3. object (reference to the object)
"COLLECTION" table (represents Collection class, driven from the class
Object):
1. id (primary key)
For example, if we have the following hierarchy:
1. Class A: public Object
a. Attribute_A1
b. Attribute_A2
2. Class B: public A
a. Attribute_B1
b. Attribute_B2
3. Class C: public Object
a. Attribute_C1: COLLECTION
b. Attribute_C2
We will have the following contents
CLASSES table:
1. 1, OBJECT, NULL
2. 2, COLLECTION, 1
3. 3, COLLECTIONITEM, 1
4. 4, A, 1
5. 5, B, 4
6. 6, C, 1
OBJECT table:
1. 1,4 (reference to A class),1 (references count)
2. 2,4 (reference to A class),1 (references count)
3. 3,5 (reference to B class),0 (references count)
4. 4,6 (reference to C class),0 (references count)
5. 5,2 (reference to COLLECTION class), 0 (references count)
6. 6,3 (reference to COLLECTIONITEM class), 0 (references count)
7. 7,3 (reference to COLLECTIONITEM class), 0 (references count)
A table:
1. 1, Attribute_A1 value, Attribute_A2 value
2. 2, Attribute_A1 value, Attribute_A2 value
3. 3, Attribute_A1 value, Attribute_A2 value
B table:
1. 3, Attribute_B1, Attribute_B2
C table:
1. 4, Attribute_C1=5 (reference to the object that represent the
collection instance), Attribute_C2 value
COLLECTION table:
1. 5
COLLECTIONITEM table
1. 6, 5 (reference to the collection), 1 (reference to the first object
on the collection)
2. 7, 5 (reference to the collection), 2 (reference to the first object
on the collection)
Here we have 6 classes, the generic class Object, class Collection,
class CollectionItem, class A, class B and class C.
And, we have 7 objects as follows:
1. object of class A, stored among tables: OBJECT, A
2. object of class A, stored among tables: OBJECT, A
3. object of class B, stored among tables: OBJECT, A, B
4. object of class C, stored among tables: OBJECT, C
5. object of class COLLECTION, stored among tables: OBJECT, COLLECTION
6. object of class COLLECTIONITEM, stored among tables: OBJECT,
COLLECTIONITEM
7. object of class COLLECTIONITEM, stored among tables: OBJECT,
COLLECTIONITEM
What I need, actually, is that API or Library that can implement like
this database, as much as possible in dynamic way.
Please, if any have come across such implementation, please inform me.
Thanks and best regards to all,
Russlan |