KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm working on a small game written in Java (but the question is language-agnostic). Since I wanted to explore various design patterns, I got hung up on the Composite pattern /Entity system (which I originally read about here and here ) as an alternative to typical deep hierarchical inheritance. Now, after writing several thousand lines of code, I'm a bit confused. I think understand the pattern and I enjoy using it. I think it's very cool and Starbucks-ish, but it feels that the benefit it provides is somewhat short-lived and (what irks me most) heavily dependent on your granularity. Here's a picture from the second article above: I love the way objects (Game entities, or whatever you want to call them) have a minimal set of components and the inferred idea is that you could write code that looks something like: BaseEntity Alien = new BaseEntity(); BaseEntity Player = new BaseEntity(); Alien.addComponent(new Position(), new Movement(), new Render(), new Script(), new Target()); Player.addComponent(new Position(), new Movement(), new Render(), new Script(), new Physics()); .. which would be really nice... but in REALITY, the code ends up looking something like BaseEntity Alien = new BaseEntity(); BaseEntity Player = new BaseEntity(); Alien.addComponent(new Position(), new AlienAIMovement(), new RenderAlien(), new ScriptAlien(), new Target()); Player.addComponent(new Position(), new KeyboardInputMovement(), new RenderPlayer(), new ScriptPlayer(), new PhysicsPlayer()); It seems that I end up having some
Tags (comma-separated)
Save Edits
Cancel