Thread: Designing Classes

  1. #1
    Registered User subdene's Avatar
    Join Date
    Jan 2002

    Designing Classes

    When you come to a business application, and you will be involved with a lot of classes and objects etc. Is best to design a base class with most of the functionality you intend to use, and then create an instance of that class. Or is better to make a class modular, i.e. using inheritance instead of putting quite a lot of code in one main class. The reason Iím asking is because I can see the modular approach to be more readable and maintainable, on the other hand you have the extra processing offset of calling the constructors from each class, and initialising them appropriately. If you are creating quite a lot of objects from an inherited class, this could cause quite a strain on processing power.
    Be a leader and not a follower.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    The real idea behind inheritance is polymorphism. If classes have no virtual functions they are probably not made to be inherited from although in some situations this is a conveinience it is generally not recommended.
    With this in mind you should try to make your base classes specify a generic interface with little or better still no implementation. The implementations of the pure virtual functions are in the derived classes.This is abstract class design.The concrete classes do all the work and the abstract classes offer the public interface.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :-

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    I agree with stoned-coder. The greatest benefit of deriving all objects from a single class is that you can quickly store pointers of completely unrelated classes within eachother, if needed, as well as for other debugging and special application purposes. Other than that, from there it should completely modular, inherited code which of course makes maintainance very easy. But as far as virtual functions, other than the more obvious ones, there is little value in using them very far down the heirarchy, reserving their use for less ambiguous roles.
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM