Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this a good OO design?

I'm building an API for myself to do 2D skeletal animation.

I have a Bone class and a Skeleton class.

The Skeleton creates a root bone and then subsequent bones are added via the Skeleton's add method by providing the parent bone.

What I now want to do is add animation and frames.

What I was thinking of, is a class that can load and interpolate animations. So it would be an object that would load an animation. It would then, at each frame, take in a Skeleton and modify the Skeleton accordingly.

Is this a good design? Should an animation take in a Skeleton, or should a Skeleton take in an animation and apply it onto itself?

like image 690
jmasterx Avatar asked Feb 24 '23 02:02

jmasterx


1 Answers

It's best to create an Animation that makes use of a Skeleton instead of the opposite. This because, logically speaking, the object Skeleton does not require an Animation to live, but an Animation strongly requires a Skeleton. So you can couple those elements in the Animation itself. Do not put too much logics in the objects, and try to put it just where necessary.

like image 61
marzapower Avatar answered Mar 13 '23 08:03

marzapower