+ Reply to Thread
Results 1 to 2 of 2

Thread: What to choose between Composition vs inheritance in C++?

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    29

    What to choose between Composition vs inheritance in C++?

    Whenever I start designing a class, I have a question in mind that what to choose between Composition vs inheritance in C++?

    What are the factors that I need to take care?

    Please help.

  2. #2
    a. Make sure inheritance models the is-a relationship. Though, this is not always the case.
    Visit: http://www.objectmentor.com/resources/articles/lsp.pdf
    b. Don't use inheritance just to get code reuse
    c. Don't use inheritance just to get at polymorphism
    d. Use composition wherever you can.
    e. Use inheritance wherever you have to.

    For more information, visit:
    http://www.artima.com/designtechniques/compoinhP.html

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts