LSP and subtypes

T

Tony Johansson

Hello!!

Assume we have a class named Base with a method called foo.

We have a subklass to this Base called Sub also with a method called foo.

Now to my question:
I'm I right if I say that if the client can use this foo from Sub instead of
foo from Base for example by using polymorfism and the client doesn't see
any difference then Sub is a subtype of Base.

What requirement is on the client program when I say client doesn't see any
difference.
Does this actually mean that the client program must be identical when
calling foo in Base and when calling foo in Sub.

//Tony
 
R

Regulus

Hello Johansson,

Useing polymorphism is OK.

you can send the client program a point : Base *pBase;
but before you send the point you must do {pBase = new Base} or {pBase
= new Sub}
So you must know which type the client program really needs.
then the client program will just call pBase->foo();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top