funcs with same names - in base and derived classes

This is a discussion on funcs with same names - in base and derived classes within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by laserlight ... means that the hierarchy does not conform to the Liskov substitution principle. Thanks for mentioning ...

  1. #16
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by laserlight View Post
    ... means that the hierarchy does not conform to the Liskov substitution principle.
    Thanks for mentioning this! Please do me a favor if you will!
    And tell me in plain English what does this principle say exactly! I could not understand it from it's definition on Wiki!

    PS:
    The function in base class is virtual and then redefined with additional argument in derived class. Does that conflict
    with the above mentioned principle?

    And anybody else besides laserlight, if you can explain the principle to me! Please do! Thanks!
    Last edited by manav; 11-30-2007 at 03:41 AM.

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    http://en.wikipedia.org/wiki/Liskov_...tion_principle

    In simple terms:
    All objects derived from base should have ALL the properties of base - and possibly extensions, but should not remove anything.

    The purpose of this is so that you can have functions that don't know about further enhancements to the base or derived class, as long as the function doesn't actually NEED to use any of the enhanced functionality of the class itself. But if you hide a base-class function with a differnet signature function, you obviously haven't got the same funcutions as base any more.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #18
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Thanks a lot matsp!
    That explanation really got into my mind! I mean thanks for nice explanation

    And that Wiki definition is too scary ^_^

    After some thought.
    Could it be possible that the redefinition was intentional.
    I mean the original writer of both the classes really wanted to hide the function in base class?
    What purpose it would serve? Is it normal practice? Is it clean software design?
    Last edited by manav; 11-30-2007 at 03:50 AM.

  4. #19
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by manav View Post
    Thanks a lot matsp!
    That explanation really got into my mind! I mean thanks for nice explanation

    And that Wiki definition is too scary ^_^
    That's why I tried to put it in simpler terms. The wiki entry is good if you are really into that sort of stuff, but it's not simple to understand.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #20
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Hey, could that redefinition be intentional? See my post edited!

  6. #21
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It COULD be intentional, but it's certainly NOT normal practice or clean design to do that - it's very UGLY design. If you want to "hide" the functionality correctly, you replace the function in the derived class with one that does nothing, or that does something else, or whatever is appropriate.

    If possible, perhaps you can ask the original author of the code?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. storing derived classes in a stl container
    By *DEAD* in forum C++ Programming
    Replies: 2
    Last Post: 10-03-2008, 07:50 PM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04:01 PM
  3. Virtual Base Classes
    By skewray in forum C++ Programming
    Replies: 11
    Last Post: 12-21-2006, 05:56 PM
  4. Help accessing classes and derived classes
    By hobbes67 in forum C++ Programming
    Replies: 8
    Last Post: 07-14-2005, 02:46 PM
  5. Inheiritance and derived classes
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2001, 02:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21