mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-14 12:58:37 +00:00
fix: Fix minor typos (#2619)
Signed-off-by: Marcel Ribeiro-Dantas <mribeirodantas@seqera.io> Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
be0d5e5953
commit
f79782bea9
@@ -19,6 +19,7 @@ As explained in the book Game Programming Patterns by Robert Nystrom, type objec
|
||||
> Allowing flexible creation of new “classes” by creating a single class, each instance of which represents a different type of object
|
||||
|
||||
## Real World Example
|
||||
|
||||
Let's consider a real-world example. Say, we are working on a game which has a hero and many monsters which are going to attack the hero. These monsters have certain attributes like attack, points etc. and come in different 'breeds' like zombie or ogres. The obvious answer is to have a base Monster class which has some fields and methods, which may be overriden by subclasses like the Zombie or Ogre class. But as we continue to build the game, there may be more and more breeds of monsters added and certain attributes may need to be changed in the existing monsters too. The OOP solution of inheriting from the base class would not be an efficient method in this case.
|
||||
Using the type-object pattern, instead of creating many classes inheriting from a base class, we have 1 class with a field which represents the 'type' of object. This makes the code cleaner and object instantiation also becomes as easy as parsing a json file with the object properties.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user