1 / 15

Design Patterns

Design Patterns. Now you are ready for Design Patterns.

Télécharger la présentation

Design Patterns

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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.com/Patterns/PatternObserver.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.com/Patterns/PatternSingleton.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.gamerservices.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 Enemy factory So that you could have several different enemies in a game • For a myspace or facebook type of application

  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

More Related