design pattern

Post on 24-Jun-2015

245 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

23 design patterns

TRANSCRIPT

Design PatternHins.Pan

Player Management

Creation Player info

Attributes

Big Trouble!

How can I generate a player with many properties?

Class inheritance ?

Class flood!

Client requirment: creation process independent

Abstract Factory

Abstract Factory

Scene

Implementation

Features

Attack property indication

Shoot

Pass

Head

Assist

……

Factory

Factory

Scene

Implementation

Features

Calculate different values

Shoot algorithm

Assist algorithm

Pass algorithm

……

Builder

Builder

Scene

Implementation

Features

Almost similar

A new player is almost the same with an existing player, shall I create him/her with factory or other better method?

Prototype

Prototype

Scene

Implementation

Features

One club one national

Use a club or a national repeatedly

Singleton

Singleton

Scene

Implementation

Features

Information mismatch

Factory accepts a uncommon info form a table, a list or other form?

How to adapt it into standard style?

Adapter

Object adapter

Composite

Class adapter

Multi-inheritance

Combine properties

How to combine so many properties into a player?

Bridge

Scene

Implementation

Features

A team and a player

Relationship between Integrity and part

But they should be represented with the same class!

Composite

Composite

Scene

Implementation

Features

New property in future

Modify composite?

Add new factory class?

Decorator

Decorator

Scene

Implementation

Features

Complex internal handle

Find a player with some condition, from where?

Facade

Facade

Scene

Implementation

Features

Fewer nationals

For number, nationals are fewer than clubs, but creating a new national cost so much, so how to handle it?

Flyweight

Flyweight

Scene

Implementation

Features

Dangerous player

Wild player to display as inconsistent, so we need a filter to handle their performance

Proxy

Proxy

Scene

Implementation

Features

Uncertain situation

For a strange data, I can’t confirm who will handle it, how to do that?

Chain of responsibility

Chain of responsibility

Scene

Implementation

Features

Decouple

How can I decouple request and handle, other than invoke directly?

Command

Command

Scene

Implementation

Features

Grammar

A language model, which is relative with language

Interpret model

Process sequentially

I want to process players which are not only in clubs, but also in nationals, sequentially, but they are different in appearance

Iterator

Iterator

Scene

Implementation

Features

Communication

Communicate between different departments, it is a multi-multi relationship, so every class has functions which are used for communication with other classes, so complex!

What shall we do?

Mediator

Mediator

Scene

Implementation

Features

History log

I want to look up a player’s history performance to determine whether to hire him.

How can I check former records?

Memento

Memento

Scene

Implementation

Features

Event mechanism

I want to update players’ experience value after a game, how can I notify them?

Observer

Observer

Scene

Implementation

Features

Player’s sick

Once a player caught a serious cold, how can I change his/her state?

State

State

Scene

Implementation

Features

Different algorithm

Beckham and Ronaldo have different algorithms for their shoot value

My god, for so many players how can I process the calculation?

Strategy

Strategy

Scene

Implementation

Features

Detail difference

Some property just has trivial difference in calculation, how can I handle this? Use strategy?

Template

Template

Scene

Implementation

Features

Just data change!

The last scene, just data change, but calculation way will not change frequently

Visitor

Visitor

Scene

Implementation

Features

Thank you!

HinsAkira@gmail.com

top related