OOP best practices?


I have a quick question about best practices for coding in panda. is there a “best” way to code your entities and characters and things? Is it better to add attributes to nodes using tags, subclass NodePath, or create another class that has the node as a property?

Ok, I guess I know that’s a meaningless question without specific context and detail, but I’m interested in general strategies, I guess.

For example: in the Asteroids example, attributes like velocity get added onto the node as tags. Another way to do it would be to make an Asteroid class, (or perhaps a Sprite class with Asteroid and Ship subclasses), and give it velocity and acceleration attributes and methods. Or maybe you could make Asteroid and Ship as subclasses of NodePath, and add the new attributes and methods to that.

Is any of those approaches better? Or is it just a matter of personal preference?

I agree that to a large extent it is a matter of personal taste but, like you, I would be interested to know what others think.

People taught OOP at college or university over the last 10 years or so would probably lean towards making everything a class, using one of the Panda classes as the base class.

More recently, there is a tendancy towards aggregation over inheritance, so making a new class with a nodepath pointing to the geometry is perhaps a more contemporary solution (and this is what I normally do).

There are advantages to just using tags as well and for lightweight classes that is possibly the best solution.