lundi 14 décembre 2015

Understanding contracts and Liskov Substitution principle

Consider the diagram :

enter image description here

Collection - an abstract class with the common part of all the others: abstract functions that put an integer in a collection and check whether the collection is empty.

Bag - a class that implements the collection as a hash, where you can find elements easily. Each element may appear more than once

I need to determine if this inheritance relationship maintain the Liskov Substitution principle.

So, i start with check if the signatures of the function are the same and they are. (put() and isEmpty()). After that, i check if the methods contracts of the two are the same, but can i have contracts to abstract class? i can't 'create' it. if they are, it's enough to say that these two class maintain the LSP? or something else is needed?

Aucun commentaire:

Enregistrer un commentaire