Design patterns principles - XOQDY/tanks-game GitHub Wiki
Design Patterns
.state/
State We created a State Pattern to utilize in Player Class to reflect the tank's current direction.
.strategy/
Strategy We use Strategy to give the AI tank the next command. We can provide a functionality to choose difficulty mode by implementing strategy in a future edition.
.command/
Command We want to utilize a Command Pattern to turn the tank's head such that the tank's next move will be in the same direction as the head.
Window.java
model/World.java
Observer Make the World and Window Classes interact using the Observer Pattern so that when the world is refreshed to the next frame, the window will know and repaint.
model/BulletPool
model/Bullet
Object Pool Rather than allocating and discarding bullets on demand, use Object Pool to establish a Bullet Pool to employ a pool of initialized bullets that are stored ready to use. We chose Object Pool since we know we'll use bullet for a short amount of time, and we don't want to have to construct new Bullet every time we require one.
Design principles
.model/
Information Expert We Assign responsibility to the class that has the information needed to fulfill it.
model/World
model/BulletPool
Creator We Assign class World the responsibility to create object tank
.model/
Polymorphism When related alternatives or behaviors vary by type (class), assign responsibility for the behavior using polymorphic operations to the types for which the behavior varies. In each object tank we have base class which is WObject.