I have a small question regarding design patterns
I have this 2 classes which extend from the very same class (doctrine_record) so they mainly have the very same methods and functions however, they now have different attributes. I'd like to create a wrapper that exposes the 2 classes summed attributes, I remember there was a pattern for this but I've been looking through the book and just couldn't find it. What I'm basically trying to do is map attributes, however since each of these classes store their data on different tables I'd have to frequently invoke the same method (save()) for each, since there are going to be plenty of classes which I'm some how going to marry I don't want to have to write the whole code for each pair of classes I have. Do you have any suggestion on how can I archive this?
To make myself more clear I'll add a simple example
I have these 2
class Content extends doctrine_record
{
int content_id;
date create_date;
date modified_date;
int number_clicks;
Content_translations translations[];
}
class Content_translations extends doctrine_record
{
int translation_id;
int content_id;
string language;
string content;
string title;
}
as you can see, 1 Content can have N Content_translations , since it's becoming a very repetitive task to work with the specific translation I need for a certain content I'd like to merge this 2 classes, avoiding modifying any of the 2.
I'm trying to have a class which I tell (better if at runtime) the 2 classes I have and it merge em so if I instance a certain content (lets call this new class sections) it'd have both classes attributes. and if I call the save() method I'd have to call it on both objects, I remember that there is a pattern like this, but I just can't remember de name of it.
What I'm basically trying to do here is the following, let's say I instance a Section (which's class is the class I'm trying to create)
so if I do this, I'd get my content and the corresponding translation in english, and I can even access the attributes of both
$section = new Section('1','en');
echo $section->number_clicks;
echo $section->title;
and if I modify any of them and call the save() method
$section = new Section('1','en');
$section->number_clicks = $section->number_clicks+1;
$section->title = "new title";
$section->save();
this would invoke the save() method on each of my 2 contained classes (content and content_translations) so the info is store on 2 different tables, now if I do this
$section = new Section('1','es');
$section->title = "titulo en español";
$section->save();
this would only alter the content_translations object sin I instanced the 'es' version of my object
Hope you can help me :) and thanks in advance