public inheritance wth advantage and disdvantage

Discussion in 'C++' started by Tony Johansson, Aug 16, 2005.

  1. Hello experts!

    My question is what advantage and disadvantage have public inheritance.

    The answer that I have to this is that sometimes it is an advantage to let a
    client have access to everything
    declared in the public section of the derived class and the base class and
    sometimed it is an disadvantage.
    Another important advantage is that wherever you can use an object of base
    class you can also use an object of it's derived class which result to using
    polymorfism.
    Sometimes it's a disadvantage to have the client be able to access everyting
    in the public section.
    If you use public inheritace and you want to use the methods in the
    implementation it's not a good idea
    because the client can access them.

    Have you any additional advantage or disadvantage to add to those that I
    have mentioned.

    Many thnaks

    //Tony
    Tony Johansson, Aug 16, 2005
    #1
    1. Advertising

  2. Tony Johansson

    Ben Pope Guest

    Tony Johansson wrote:
    > Hello experts!
    >
    > My question is what advantage and disadvantage have public inheritance.
    >
    > The answer that I have to this is that sometimes it is an advantage to let a
    > client have access to everything
    > declared in the public section of the derived class and the base class and
    > sometimed it is an disadvantage.
    > Another important advantage is that wherever you can use an object of base
    > class you can also use an object of it's derived class which result to using
    > polymorfism.
    > Sometimes it's a disadvantage to have the client be able to access everyting
    > in the public section.
    > If you use public inheritace and you want to use the methods in the
    > implementation it's not a good idea
    > because the client can access them.
    >
    > Have you any additional advantage or disadvantage to add to those that I
    > have mentioned.


    It's not really about "advantages/disadvantages", they represent different relationships.

    If you publicly inherit from a base class then the derived class "is a" type of base class, the base class can be "substituted by" a derived class. The whole point of public
    inheritance is polymorphism.

    Private inheritance means that the derived class is "implemented in terms of" or composed from the base class.

    Have you read sections 19-25:
    http://www.parashift.com/c -faq-lite/

    Ben
    --
    I'm not just a number. To many, I'm known as a String...
    Ben Pope, Aug 16, 2005
    #2
    1. Advertising

  3. Tony Johansson wrote:
    > My question is what advantage and disadvantage have public inheritance.


    It depends on what you consider "advantage" or "disadvantage", doesn't it?

    > The answer that I have to this is that sometimes it is an advantage to let a
    > client have access to everything
    > declared in the public section of the derived class and the base class and
    > sometimed it is an disadvantage.


    Good answer. Does this actually provide any information? It's like when
    asked about the climate in Norway, you'd say, "Sometimes it rains and some
    other times the sun's shining". No information whatsoever, except that it
    doesn't rain all the time.

    > Another important advantage is that wherever you can use an object of base
    > class you can also use an object of it's derived class which result to using
    > polymorfism.


    It doesn't necessarily involve polymorphism.

    > Sometimes it's a disadvantage to have the client be able to access everyting
    > in the public section.


    Like, when?

    > If you use public inheritace and you want to use the methods in the
    > implementation it's not a good idea
    > because the client can access them.


    Huh?

    > Have you any additional advantage or disadvantage to add to those that I
    > have mentioned.


    I think you're thinking too much into that. What's the advantage and
    disadvantage of addition? How about division? And multiplication? All
    those operations are necessary in certain situations.

    Public inheritance exists to specifically model the "is-a" relationship.
    An object of the derived class can be used where an object of the base
    class is expected. The language provides a conversion between the two.
    If you don't want public members of the base class to be accessible via
    the derived class object, don't use public inheritance.

    V
    Victor Bazarov, Aug 16, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    1
    Views:
    1,298
    smith
    Dec 8, 2004
  2. Wayne Myers

    POK Flag Weirdness wth binary files

    Wayne Myers, May 26, 2004, in forum: Perl
    Replies:
    1
    Views:
    465
    ! aaa
    May 27, 2004
  3. SpamProof
    Replies:
    0
    Views:
    521
    SpamProof
    Oct 21, 2003
  4. Kausar Parveen
    Replies:
    4
    Views:
    239
    Kausar Parveen
    May 31, 2006
  5. Miika Parvio

    problem wth rubyclr and win32 service

    Miika Parvio, Apr 21, 2008, in forum: Ruby
    Replies:
    2
    Views:
    118
    Miika Parvio
    Apr 22, 2008
Loading...

Share This Page