Class design (inherit or not)

This is a discussion on Class design (inherit or not) within the Game Programming forums, part of the General Programming Boards category; Really just a question of security. I have two classes i am rewriting (safety issues). 1) class Surface - this ...

  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
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    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, 11: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, 09: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, 09:55 AM
  4. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 02:03 AM
  5. Replies: 4
    Last Post: 12-29-2002, 12:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21