I am in the design process of an RPG game and I have no experience at all in game dev. This question is about how I should approach entity management using OOP classes.

My train of thought is as followed:

  • Have Entity interface with basic update() function
  • "Mortal" class and "NPC" class implement Entity
  • "Hero" and "Monster" class inherit from "Mortal" class

In this case, Mortal class are all those entities that have statuses such as HP and MP. NPC are self explanatory.

I am sure my approach is naive so I would like to know the pros and cons and what would be a better way to approach this.

  • 2
    \$\begingroup\$ This question is very broad and can produce a variety of results without any of it beeing correct or wrong. Maybe add some explanations of problems you encounter or pitfalls you foresee \$\endgroup\$
    – floAr
    Commented Nov 25, 2013 at 6:51
  • \$\begingroup\$ If you are new to game design you should avoid writing what seems like a game engine. You are correct in creating an entity interface with update functions but many game engines already have this kind of setup for you. For example if you use Unity all the lifecycle functions you need are created and you just need to fill them with logic. Anyway your approach for interfacing is correct. Although you might want to have your NPC also inherit from Mortal just so you can have something like guards or maybe even NPCs that follow and help you without command. \$\endgroup\$ Commented Nov 26, 2013 at 23:15

1 Answer 1


Your approach is fine, and was used widely by game developers of the past. You see with inheritance hierarchy you often find yourself in a situation there you want inherit from a multiple classes, but they don't usually mix well (including The diamond problem). Because of that, a component based architecture is being widely adopted. One variation of this approach is called Entity component system or ECS. This approach uses composition instead of inheritance to build up functionality of the entity (note that entity have a very special meaning in ECS). If you are interested in ECS here is some references for you to start: one, two, three.

As Sean Middleditch correctly noticed ECS is just one type of implementation, you are free to use other approaches.

As a side note, I really suggest you not concentrate much on architecture for your first attempts. It's really hard to make all right and nice in games. There are many other aspects which are important for a novice: handling game loop, input, graphics, sound, physics, collision detection, and the list goes on. You should try to make small game (like Tetris or Breakout) ignoring architecture nuances, to become comfortable with your tools, and see the whole picture.

  • 2
    \$\begingroup\$ "not concentrate much on architecture for your first attempts" good advice indeed. It's far more important that the early stages of any new game be simple and flexible because designs and requirements will change and all the time spent architecting elaborate solutions will hold you back. \$\endgroup\$ Commented Nov 25, 2013 at 3:48
  • \$\begingroup\$ @PatrickHughes "not concentrate much on architecture for your first attempts" I would take this advice anytime over the component entity architecture non-sense I see all over the place. \$\endgroup\$
    – concept3d
    Commented Nov 25, 2013 at 5:30
  • \$\begingroup\$ @PatrickHughes your answer makes it sound as if ECS is less flexible, nothing could be further from the truth. \$\endgroup\$
    – CodeSmile
    Commented Nov 25, 2013 at 11:45
  • \$\begingroup\$ "Entity component system or ECS is being widely adopted" - usual pedantry from me, but ECS is not that widely adopted compared to component-based design in general (there are many ways to structure and use components and ECS is a subset of them). \$\endgroup\$ Commented Nov 25, 2013 at 23:27
  • \$\begingroup\$ @SeanMiddleditch agreed. ECS is just seems to me like a well defined approach, compared to other implementations. However I update answer for a full picture. \$\endgroup\$
    – pabdulin
    Commented Nov 26, 2013 at 2:15

Not the answer you're looking for? Browse other questions tagged .