Presentation is loading. Please wait.

Presentation is loading. Please wait.

Design Patterns. Now you are ready for Design Patterns Design patterns are recurring solutions to software design problems you find again and again in.

Similar presentations


Presentation on theme: "Design Patterns. Now you are ready for Design Patterns Design patterns are recurring solutions to software design problems you find again and again in."— Presentation transcript:

1 Design Patterns

2 Now you are ready for Design Patterns Design patterns are recurring solutions to software design problems you find again and again in real-world application development. Patterns are about design and interaction of objects, as well as providing a communication platform concerning elegant, reusable solutions to commonly encountered programming challenges. The Gang of Four (GoF) patterns are generally considered the foundation for all other patterns. They are categorized in three groups: Creational, Structural, and Behavioral.

3 Observer pattern (behavioral) Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. http://www.dofactory.c om/Patterns/PatternOb server.aspx#_self2

4 This is the class diagram from the Observer Pattern Example

5 When would I use the Observer Pattern? When you want to notify Investor objects of a change in a Stock object (say the price changed) When you want to notify Avatar objects of a change in a Boss object (say the boss is loosing health and you want to make sure all the avatars trying to kill him are notified)

6 Singleton Pattern (creational) Ensure a class has only one instance and provide a global point of access to it. http://www.dofactory.c om/Patterns/PatternSin gleton.aspx#_self2 http://www.dofactory.c om/Patterns/PatternSin gleton.aspx#_self2

7 Singleton Pattern Example Class Diagram

8 When would l use the Singleton Pattern? LoadBalancing object Only a single instance (the singleton) of the class can be created because servers may dynamically come on- or off-line every request must go through the one object that has knowledge about the state of the (web) farm. A game service is a game component that uses an interface to enforce a singleton pattern and make a single instance of a game component accessible to all other components A game service is a built in mechanism that allows a game to create and manage a single instance of a component and allows other components access to the service. Good candidates for a game service are. – InputHandler – GameConsole – Profiling Service – Scoreboard Gamer Services in the XNA Framework – http://msdn.microsoft.com/en- us/library/microsoft.xna.framework.g amerservices.aspx

9 Factory Method Pattern (creational) Creates an instance of several derived classes Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

10 Here is the class diagram

11 When would I use the factory pattern? Website factory For a myspace or facebook type of application Enemy factory So that you could have several different enemies in a game

12 How would I make levels in my game?

13 The answer is a pattern The abstract factory pattern – Creates an instance of several families of classes – Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

14 Class Diagram for the Abstract Factory

15 Homework Start working on your Design Patterns Presentation (this is due at the end of the semester) Study for the midterm (next week) Finish(work on) your game. (this is due after spring break) Read DesignPatterns- TheIndieStoneCommunity.pdf


Download ppt "Design Patterns. Now you are ready for Design Patterns Design patterns are recurring solutions to software design problems you find again and again in."

Similar presentations


Ads by Google