72
Design Pattern Hins.Pan

Design pattern

Embed Size (px)

DESCRIPTION

23 design patterns

Citation preview

Page 1: Design pattern

Design PatternHins.Pan

Page 2: Design pattern

Player Management

Page 3: Design pattern

Creation Player info

Page 4: Design pattern

Attributes

Page 5: Design pattern

Big Trouble!

How can I generate a player with many properties?

Class inheritance ?

Class flood!

Client requirment: creation process independent

Page 6: Design pattern

Abstract Factory

Page 7: Design pattern

Abstract Factory

Scene

Implementation

Features

Page 8: Design pattern

Attack property indication

Shoot

Pass

Head

Assist

……

Page 9: Design pattern

Factory

Page 10: Design pattern

Factory

Scene

Implementation

Features

Page 11: Design pattern

Calculate different values

Shoot algorithm

Assist algorithm

Pass algorithm

……

Page 12: Design pattern

Builder

Page 13: Design pattern

Builder

Scene

Implementation

Features

Page 14: Design pattern

Almost similar

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

Page 15: Design pattern

Prototype

Page 16: Design pattern

Prototype

Scene

Implementation

Features

Page 17: Design pattern

One club one national

Use a club or a national repeatedly

Page 18: Design pattern

Singleton

Page 19: Design pattern

Singleton

Scene

Implementation

Features

Page 20: Design pattern

Information mismatch

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

How to adapt it into standard style?

Page 21: Design pattern

Adapter

Page 22: Design pattern

Object adapter

Composite

Page 23: Design pattern

Class adapter

Multi-inheritance

Page 24: Design pattern

Combine properties

How to combine so many properties into a player?

Page 25: Design pattern

Bridge

Scene

Implementation

Features

Page 26: Design pattern

A team and a player

Relationship between Integrity and part

But they should be represented with the same class!

Page 27: Design pattern

Composite

Page 28: Design pattern

Composite

Scene

Implementation

Features

Page 29: Design pattern

New property in future

Modify composite?

Add new factory class?

Page 30: Design pattern

Decorator

Page 31: Design pattern

Decorator

Scene

Implementation

Features

Page 32: Design pattern

Complex internal handle

Find a player with some condition, from where?

Page 33: Design pattern

Facade

Page 34: Design pattern

Facade

Scene

Implementation

Features

Page 35: Design pattern

Fewer nationals

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

Page 36: Design pattern

Flyweight

Page 37: Design pattern

Flyweight

Scene

Implementation

Features

Page 38: Design pattern

Dangerous player

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

Page 39: Design pattern

Proxy

Page 40: Design pattern

Proxy

Scene

Implementation

Features

Page 41: Design pattern

Uncertain situation

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

Page 42: Design pattern

Chain of responsibility

Page 43: Design pattern

Chain of responsibility

Scene

Implementation

Features

Page 44: Design pattern

Decouple

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

Page 45: Design pattern

Command

Page 46: Design pattern

Command

Scene

Implementation

Features

Page 47: Design pattern

Grammar

A language model, which is relative with language

Interpret model

Page 48: Design pattern

Process sequentially

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

Page 49: Design pattern

Iterator

Page 50: Design pattern

Iterator

Scene

Implementation

Features

Page 51: Design pattern

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?

Page 52: Design pattern

Mediator

Page 53: Design pattern

Mediator

Scene

Implementation

Features

Page 54: Design pattern

History log

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

How can I check former records?

Page 55: Design pattern

Memento

Page 56: Design pattern

Memento

Scene

Implementation

Features

Page 57: Design pattern

Event mechanism

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

Page 58: Design pattern

Observer

Page 59: Design pattern

Observer

Scene

Implementation

Features

Page 60: Design pattern

Player’s sick

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

Page 61: Design pattern

State

Page 62: Design pattern

State

Scene

Implementation

Features

Page 63: Design pattern

Different algorithm

Beckham and Ronaldo have different algorithms for their shoot value

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

Page 64: Design pattern

Strategy

Page 65: Design pattern

Strategy

Scene

Implementation

Features

Page 66: Design pattern

Detail difference

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

Page 67: Design pattern

Template

Page 68: Design pattern

Template

Scene

Implementation

Features

Page 69: Design pattern

Just data change!

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

Page 70: Design pattern

Visitor

Page 71: Design pattern

Visitor

Scene

Implementation

Features

Page 72: Design pattern

Thank you!

[email protected]