Skip to content

Commit c79d8da

Browse files
committed
Updated readme
1 parent 80a10bf commit c79d8da

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

_text/12-type-object.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ The Type Objects should share the same interface (or parent) to make it easier f
88

99
**When is it useful?**
1010

11-
- When you can't (or don't want to) use class inehritance. Let's say you make a game with animals. You have a base class which is parent to all animals, and then as children to that class you add birds, fish, and mammals. In the bird class you define a flying behavior, which is all fine until you add an ostrich, which can't fly. In that case you have to inherit from the bird class and create new children that can fly and can't fly. But what about bats, which is a mammal that can fly? You don't want to add flying behavior in two separate classes! A better way is to define a flying and a non-flying type in a separate class, so both ostriches remain on the ground and bats can fly.
11+
- When you can't (or don't want to) use class inehritance. Let's say you make a game with animals. You have a base class which is parent to all animals, and then as children to that class you add birds, fish, and mammals. In the bird class you define a flying behavior, which is all fine until you add an ostrich, which can't fly. In that case you have to inherit from the bird class and create new children that can fly and can't fly. But what about bats, which is a mammal that can fly? You don't want to add flying behavior in two separate classes! A better way is to define a flying and a non-flying type in a separate class, so both ostriches remain on the ground and bats can fly.
12+
13+
- In game event systems, the Type Object can be used to define event types as objects. This allows for dynamic registration and handling of different event types during runtime, making the event system more versatile and adaptable.
14+
15+
- Can be used to manage game configuration and settings. By representing different configuration options or settings as objects, you can dynamically switch between different configurations.
16+
17+
- If you need to switching type at runtime.
1218

1319
**Related patterns**
1420

0 commit comments

Comments
 (0)