I notice that some yii-classes difficult to extend. This is because of methods of a superclass are used directly inside a subclass.
For example in old Yii1.1.14 I see this code:
if(($table=$model->getDbConnection()->getSchema()->getTable($tableName))===null)
throw new CDbException(Yii::t('yii','The table "{table}" for active record class "{class}" cannot be found in the database.',
array('{class}'=>$this->_modelClassName,'{table}'=>$tableName)));
So as you can see class CActiveRecord is tight binding with CDbConnection. I propose use wraper for methods in derived classes if it is not used yet in Yii2.
Notice! These methods interacts with other classes and gets or returns objects of other classes. So common simple methods of subclasses doesn’t need to have wrapers.
For example:
class BaseClass
{
public function addValue($FooClass1, $params)
{
/* This is method that interacts with other classes.
Other classes ($FooClass1) can be extended and new functionality and properties can be used in extended $FooClass1 class. */
//do something
}
}
class SubClass extends BaseClass
{
/* There is the using of method addValueMethod() of parent class in this method.
So it is needed to create wraper method to ease the extending this class and FooClass1 class.
Both SubClass and FooClass1 can be easy extended later. */
public function doSomething()
{
$FooClass1=new FooClass1; //Some class is here
$params=aray(); //Some parameters are here
$this->addValueWraper($FooClass1, $params);
//$this->addValue($FooClass1, $params)
//It is incorrect to use addValue() method in this way because of we can't redefine easy method doSomething() in derived class. We need to copy all logic from here to derived class to make same functionality.
}
/* We can easy redefine this method in derived class to add extra operation or data in process of interaction between classes.
it is better to use wraper for cases when FooClass1 can be extended and FooClass1 can receive new properties and so on. */
public function addValueWraper($FooClass1, $params)
{
$this->addValue($FooClass1, $params);
}
}
/* SubSubClass is the new class that anybody can create on his own*/
class SubSubClass extends SubClass
{
public function addValueWraper($FooClass1, $params)
{
//We can easy modify $params and do other things if we want. We can use not FooClass1 but its derived class, so we can consider it here without modifing any other methods or classes.
$this->addValue($FooClass1, $params);
}
}
It will be easy for me to use and to extend core yii-classes and their core-subclasses if wrapers will be used.