Hacker News new | ask | show | jobs
by TheOtherHobbes 3701 days ago
> never going to actually implement anything like a car on an animal in a real program.

Did you mean "on" or "or"?

Using OOP to implement a vehicle is a no-brainer. It's a completely standard model for games.

Extending the animal class to make a car would be weird though.

One point of OOP isn't that you make classes, but that the classes you make can be easily duplicated and automated.

So you can make an animal with a few simple behaviours, use your animal prototype to make a herd or flock, and suddenly you've got emergent semi-intelligence, which you can define by changing a few lines in the prototype.

It's not just a way of giving properties to something that's kind of like a real object - it's a way of simplifying automation and bulk updates of related entities.

1 comments

>Extending the animal class to make a car would be weird though.

Carriage extends Animal with Cart Car implements Carriage with Engine as Animal

That sounds more like composition then inheritance.