Limiting DataAccess::update()
to accept your child Model
breaks the contract of this interface.
True, all Model
objects are of class SplSubject
, but not all SplSubject
are of class Model
. An interface is a contract guaranteeing that an implementing class it supports everything the interface supports.
Your code, if it worked would be limiting the DataAccess::update()
method to only the Model
sub class and not the wider parent class SplSubjects
. You cannot narrow the scope of the parameter passed to method defined by an interface.
Let's say you added a property public $foo
to the Model class. If it were allowed, you could in your DataAccess::update()
method you uses that property $foo
. Someone could come along and extend SplSubjects
to a child OddModel
which didn't have a $foo
property. They could no longer pass the OddModel
into your DataAccess::update()
function--if they could it would break as no $foo
property exists for the OddModel
.
This is the whole idea behind interfaces, by implementing they you agree 100% to support what is defined by the interface. In this case your interface says:
if you implement me, you must accept every
SplSubject
or class that extendsSplSubject
You're implementation of the interface attempts to break the contract.