I am thinking of how to implement the building of stuff in a clean way. The following things have to be done.
- can i build in this town
- do i have the resources
- do i own the required buildings
- is there a upgrade in queue for this type of building
I am deeply concerned that if I implement this in a if/else switch case way, the result will be inflexible. So i guess i will implement the strategy pattern for all the ways to build.
Wikipedia:
In computer programming, the strategy pattern (also known as the policy pattern) is a particular software design pattern, whereby algorithms can be selected at runtime.
In some programming languages, such as those without polymorphism, the issues addressed by this pattern are handled through forms of reflection, such as the native function pointer or function delegate syntax.
This pattern is invisible in languages with first-class functions. See the Python code for an example.
The strategy pattern is useful for situations where it is necessary to dynamically swap the algorithms used in an application. The strategy pattern is intended to provide a means to define a family of algorithms, encapsulate each one as an object, and make them interchangeable. The strategy pattern lets the algorithms vary independently from clients that use them.
Lots of nonsense written here. Fowler or one of his writers for the Signature Series has brought this to a better point. Ill try to look it up. Till then you have to stay with this lousy definition