I helped design and implement and Droid API written in PHP. Though it works just fine, I am always looking to refactor my code.
Is it ok to have objects within other objects that have a common ancestor?
This may be an elementary question, but I can't seem to find information to support whether or not this is poor practice.
The goal is to have class foo provide common constants and methods to all.
Example:
abstract class foo {
//constants
//common methods to all
}
class bar extends foo{
//represents something
}
class widget extends foo {
//represents something else
}
class controller extends foo{
//controls flow
public function __construct(){
$this->my_bar= new bar();
$this->my_widget= new widget();
}
}
Classes bar and widget may not need to extend foo, but methods within those objects wouldn't know about the common things that foo knows without sending parameters.
There seems to be too much redundancy going on, just looking for a best-practice.