Friday, 15 June 2012

oop - When Liskov Substitution refers to subtypes, is it talking about derived classes in the context of C#? -



oop - When Liskov Substitution refers to subtypes, is it talking about derived classes in the context of C#? -

i'm unfamiliar word 'subtype' after looking @ the wikipedia article.

i took liskov substitution mean if have method takes animal, should able pass in cat or animal cat : animal without unintended side effects.

is liskov substitution refers to?

exactly. takes animal should able take dog, cat, , subclasses (breeds, if like). methods compatible.

note preconditions cannot strengthened in subtype, nor can postconditions weakened. otherwise slot in particular subtype , break because surrounding code had imposed preconditions subclass couldn't tolerate. can hard implement in practise - see the circle/ellipse problem more info.

c# oop solid-principles

No comments:

Post a Comment