I'm trying to solve a design puzzle in the most efficient way, but I tend to end thinking that I really need a multiple inheritance here. So, here I am, asking the pros. I'm creating an active-record lib that will perform almost identical actions with different name and value variables. I'm on PHP 5.2.13
Suppose I have these classes:
class Property {
protected $_props = array();
function set($name, $value) {
$this->_props[$name] = $value;
};
}
class ColorProperties extends Property {
function red($value) {
$this->set('red', $value);
}
function blue($value) {
$this->set('blue', $value);
}
}
class LayoutProperties extends Property {
function x($value) {
$this->set('x', $value);
}
function y($value) {
$this->set('y', $value);
}
}
Now I need to create a class ShapeProperties that will inherit from both, ColorProperties and LayoutProperties. So that:
$shape = new ShapeProperties();
$shape->x(10);
$shape->red(255);
The reason why I need it that way, is to have auto-completion in IDE with huge PHPDoc comment block for each property. So, seems that I'm leaning towards copy/paste out of despair.
OLD BODY (BEFORE EDITS)
I've got these classes (blocks):
class Red {
function red();
}
class LightRed {
function light_red();
}
class Blue {
function blue();
}
class LightBlue {
function light_blue();
}
class Green {
function green();
}
class LightGreen {
function light_green();
}
And now I need to build a numerous amount of classes using these blocks, ie:
class RGB extends Red, Green, Blue {
function red();
function blue();
function green();
}
class RLRB extends Red, LightRed, Blue {
function red();
function light_red();
function blue();
}
So if I switch word class with interface, I'll get what I need, but I need working implementation without loads of boilerplate code. Is there a way/approach to work this around in PHP?
Colorclass in reality, it was just to illustrate that methods are being inherited. The action is always the same in each method:function _method_name_($value) { $this->set('_method_name_', $value); }. Please refer to EDIT 2 to get more clear picture.