Results 1 to 3 of 3

Thread: What is best inheritate or use methods of public object ?

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default What is best inheritate or use methods of public object ?

    I have a doubt.
    I can have a class A that inheritates another B, so I can use methods of B.
    But I could have a public B object creates inside A, in this case I could use B-methods also.

    What is best ? What is fast to compile ? What is fast to run ?
    Thanks.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: What is best inheritate or use methods of public object ?

    You use inheritance if A is somehow an extended B: a simple example is a class Car and Engine: a Car instance has an Engine and it's not logical that Car derives from Engine (even if Car functionality needs the Engine), but an My_Custom_Designed_Car could derive from Car (and can use the public functionality of a Car just like if it is a Car including some functionality that start movement (using the engine ).

    So if A is an B and it makes sense that A is used like*** an B use inheritance. ***including the polymorphic (virtual) member-function calls

    LE: switched the A and B (i first read class B : public A instead of what you said class A : public B - code makes it simpler)
    Last edited by Zlatomir; 24th February 2012 at 12:44.

  3. #3
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What is best inheritate or use methods of public object ?

    prefer composition over inheritance where the aim is just code re-use.

    Write your code with readability and maintenance in mind, NOT speed of compiling or running.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Mapping of .ui elements to object methods
    By KieranS in forum Qt Tools
    Replies: 2
    Last Post: 5th November 2009, 21:33
  2. Why Qt can not find a public slot?
    By Alex Snet in forum Qt Programming
    Replies: 13
    Last Post: 13th April 2009, 08:31
  3. Replies: 2
    Last Post: 14th October 2008, 09:05
  4. private and public slots ??
    By salmanmanekia in forum Qt Programming
    Replies: 2
    Last Post: 13th August 2008, 11:49
  5. GUI Look and Feel -- public repository available?
    By Byngl in forum Qt Programming
    Replies: 2
    Last Post: 28th November 2006, 06:37

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.