Thread: Class design (inherit or not)

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    673

    Class design (inherit or not)

    Really just a question of security.
    I have two classes i am rewriting (safety issues).
    1) class Surface - this is basicly just a smart(kinda) wrapper for SDL_Surface
    2) class Animation - this is obvious, but it uses a reference to Surface right now.
    They both reside in the Varia::Graphics::<CLASS> namespace, but I was wondering if I should have Animation inherit Surface or just keep passing the reference?

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Is an animation a surface? If not inheritance is not the correct design. I think it's more along the lines that a surface has a or can have an animation. Therefore aggregation would be my choice.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    What is aggregation? Stuff I have found on google just doesn't explain it good enough.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Aggregation is where an object includes another object, either as "full member variable", or as a pointer/reference to the actual variable.

    In you case, perhaps something like this:
    Code:
    class Animation
    {
    ...
        Surface surface;
    ...
    }
    --
    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. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    Oh ok thank you Bubba, and matsp.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help on class coupling
    By andrea72 in forum C++ Programming
    Replies: 4
    Last Post: 04-17-2011, 10:16 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. Looking for a little assistance with item class design...
    By Raigne in forum Game Programming
    Replies: 5
    Last Post: 10-22-2008, 08:55 AM
  4. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  5. Replies: 4
    Last Post: 12-29-2002, 12:29 AM