dimanche 29 octobre 2017

Why are variables not part of the contract in interfaces?

Today I stumbled across the observer pattern. In most versions the concreteObserver HAS-A concreteSubject as one of its instance variables. This is, in order to get information about the changed state of the subject.

Generally spoken, why don't we simply put the variable into the IObserver interface? This way the "contract with the outer world" interfaces impose on classes would not only apply to methods but also for variables? Wouldn't that be a good thing because programmers would be more guided towards implementing the interface or certain patterns that are based on interfaces?

Aucun commentaire:

Enregistrer un commentaire