I have this function in 3 classes because they all use the same objects. In the effort to not repeat the code in each class should I extract it out into a parent class? If it is a matter of preference i’d like to.
This function was created to implmenet the dependency injection pattern ( a misnomer in my opinion as it removes depedencies).
public function setObjects($DatabaseObject, $TextObject, $MessageObject)
{
$this->DatabaseObject = $DatabaseObject;
$this->TextObject = $TextObject;
$this->MessageObject = $MessageObject;
}
Yes, you should always create DRY code wherever possible, so if it will apply to all child classes, move it to the parent class and let classes override if necessary.
Also, it is called dependency injection because you inject the dependency instead of creating it inside your class.