← 返回 akunacapital 的题目列表Design an Enemy Factory
类型:online_judge
Design an Enemy factory to return different enemy instances.
Suppose you are working for a very large online micro-multiplayer game company. In this game, there is a subsystem responsible for managing all the enemies. We would like you to create a factory to instantiate all these enemies. To simplify, assume each enemy only has one property: color. Therefore, you need to provide a factory where you specify the color of the enemy you want, and it will return an instance of the enemy based on that specified color.
Follow-up: The Enemy object consumes a lot of memory, and there are tons of Enemy objects being created. How would you design the system to mitigate this?
Example
Input
red