Im sorry in forward, Im sure I wont be able to express myself well. Its a game system:
abstract class GameType
{
private $score;
public __constructor($score)
{
$this->score = $score;
}
public abstract function getName();
public function getScore()
{
return $this->score;
}
}
final class Soccer extends GameType
{
public function getName() :
{
return 'soccer';
}
}
final class Basketball extends GameType
{
public function getName() :
{
return 'basket ball';
}
}
final class Hockey extends GameType
{
public function getName() :
{
return 'hockey';
}
}
this illustrates 3 kind of games, each can be scored, all has different names (I know, getName() could be replaced with constants, but lets forget it for now)
Now this seems to be fine and system-independent, lets say it's being developed by a team with FRAMEWORK A and it can be passed to another system developed by FRAMEWORK B
Until now. A new requirement, lets send an email if a score takes place:
abstract class GameType
{
private $score;
public __constructor($score)
{
$this->score = $score;
}
public abstract function getName();
public abstract function notifyIfScored();
public function getScore()
{
return $this->score;
}
}
final class Soccer extends GameType
{
public function getName() :
{
return 'soccer';
}
public abstract function notifyIfScored()
{
FRAMEWORK1::sendEmail('score 1');
}
}
final class Basketball extends GameType
{
public function getName() :
{
return 'basket ball';
}
public abstract function notifyIfScored()
{
FRAMEWORK1::sendEmail('score 2');
}
}
final class Hockey extends GameType
{
public function getName() :
{
return 'hockey';
}
public abstract function notifyIfScored()
{
FRAMEWORK1::sendEmail('score 3');
}
}
sending email is tied to FRAMEWORK1, but even if we could pass it outside as Dependency Injection, its still looks like the class has to do "more" and by doing this, it looses the independence of ANY framework.