> For instance I've left the function "move" out of this base class as I don't know whether to have
> a MoveableSprite derivation of this base or PhysicsSprite or things such as SpriteWithAnimation
We would have to iterate over the class hierarchy design a few times before committing on a particular interface for the base class. If this is he first attempt at writing a program for this domain, a throw-away design prototype to support iterative incremental refinement would be useful.
> I am really struggling to figure out what a class should have and shouldn't have.
In general, it is easier to add more functionality to a class when it is clear that requirement exists, than to remove functionality at a later stage when we realise that it is not needed or that it is better to provide it in some other component.
> If I new a child class and store it in it's parent class, when I perform delete on parent class,
> will it release the entire memory using by the child?
Yes, provided the vase class destructor is virtual.
Almost always, a base class should have a virtual destructor; delete on a pointer to base, where the object involved is of a derived class, engenders undefined behaviour if the destructor in the base class is not virtual.
Ideally make the class at the root of a hierarchy a pure interface: a collrction of pure virtual functions with no implementation other than explicitly defaulted foundation operations.
See: Rule of zero (rule of five defaults):
http://en.cppreference.com/w/cpp/language/rule_of_three
> I would like to keep drawing and physics seperated so I can experiment with multi-threading.
Even if concurrency is not involved, keeping separate concerns separate is fundamental to robust, maintainable designs.
In the class outlined (
MySprite)
Avoid raw owning pointers; consider using a smart pointer for things like this:
Avoid returning const-qualified values (in this case - return a scalar value - the compiler is required to ignore the const). And make the code cost correct:
1 2
|
// const bool getEnabled() { return enabled; }
bool getEnabled() const { return enabled; }
|