I’m working on software which makes use of various design patterns and consequently also a lot of polymorphism by extending various class in different way to create factory, builder and composite etc patterns.
Now the problem I’m facing, or which I might be implementing incorrectly is that I’m not sure the extending of class/objects within the database/model is working the way I thought it was suppose to work, but please correct me if I’m wrong. I’ll try and add xml code to try and help explain what I’m depicting...
Now let’s say we have class Product which extends from xPDOSimpleObject with it’s associated attributes and relationships within that class/object. Now we may have a SpecializedProductA and SpecializedProductB which extends Product. In effect both of these are xPDOSimpleObject classes/objects but each with the own set of additional and different attributes. This should be fairly straight forward to understand.
<object class="Product" table="test_Product" extends="xPDOSimpleObject">
...
</object>
<object class="SpecializedProductA" table="test_SpecializedProductA" extends="Product">
...
</object>
<object class="SpecializedProductB" table="test_SpecializedProductB" extends="Product">
...
</object>
Now upon executing the save method to save the specialized products I would thinks that the product attributes within this hierarchy will be saved within the modx_test_Product class, and the additional attributes of the specialized classes respectively in modx_test_SpecializedProductA and modx_test_SpecializedProductB. What appears to be happening is that SpecializedProductA creates a table with all the attributes from Product as well as it’s own additional attributes which I don’t want, as I want the information (or data) which is relevant to the specific object to be saves in their respective tables, not everything in one table.
I found the problem when I wanted to exploit the usage of using the modResource class/object as a base/parent class which Product would extend, so that when I save a Product object, that the modResource attributes are still saves in modx_site_content and the Product attributes in modx_test_Product, but what happens is all the attributes found in modResource is nou saved in modx_test_Product which means the Product which is actually a type of modResource is never shown on the resource tree as it is never saved in the correct place.
<object class="Product" table="test_Product" extends="modResource">
...
</object>
How would one approach such a scenario for this to work correctly? I’ve recently noticed a class_key attribute in some tables, does this have something to do with it? Because let’s say I need a specialized user class/object would I extend modUser but in the modx_users table change the class_key to ’SpecializedUser’? And where does it save the additional attributes then?
<object class="SpecializedUser" table="users" extends="modUser">
...
</object>
Sorry for all the reading and question, but I’m trying to learn more about how to use modx and xpdo as it is one of the most awesome cms’s (or cmf’s) I’ve ever come across and for future project where we used to use Joomla for only start using modx now because it is so awesome!