Say I have a base class Base and it’s subclasses SubA and SubB.
public class Base(){
public (static?) Animation anim;
public Base(Frame[] frames){
CpuIntensiveAnimationCreation(frames);
// I need only one 'instance' of Animation Per subclass.
// Every different TYPE of subclass needs it's own Animation instance.
// A subclass can share one Animation, among multiple subclass-instances. (static?)
}
See, I don’t want to initialize a new Animation instance for every instance of a subclass I make, since it takes quite some time. I do however need every subclass to have it’s own Animation.
I could ofcourse have a static Animation per subclass and not use a superclass, but that would require a lot of redundant/copied code.
How should I get to this?
My suggestion would be to have an abstract method
getAnimation()in the base class.Subclasses could then override this method to return a static Animation per subclass.