Thursday 26 September 2013

Design Patterns

In this lecture we learned about design patterns. Design patterns are like the solutions to making your programming easier to control. They can prevent long and tiresome amounts of code by allowing you to use reusable ones. That is why we revised OOP in the last class. Using inheritances, classes and polymorphisms can solve the problem of having way too much code in your game. It is a good way ease up the load in your programming by using design patterns. Professor Hogue described four different types of patterns that can be used in our game this year.

Singleton

A singleton pattern is a class that instantiates an object one time. So instead of using a globally defined object, you can use a static variable in your singleton class. That way the object will only have one instance. Hence the word "Singleton", "single". Get it? 


Facade

A facade pattern is a set of classes interact with each other in a subsystem. Only one class exchanges data with another class within another subsystem containing interactive classes.



State

State patterns is like a using switches() and enums. It's like having a group of code do its own set of instructions. In the end, you will eventually merge the states together by calling them in an update().


This decreases the amount of errors which occur in your program. 



Factory

A factory pattern is a single point of a class entrance for the creation objects. It's just like an actual factory that builds many of the same products. When it is ready to be manufactured it is shipped to its location. The same thing is with a factory pattern, it creates many objects  for specific function. Factory pattern is also good for organizing memory allocation.


Design patterns are a very good practice to use especially if you like order and neatness in your code. You can use these kinds of patterns to further improve your programming style.

No comments:

Post a Comment