Design Patterns Summer Course 2009-2010 - Session#4

Post on 10-Jun-2015

143 views 0 download

Tags:

Transcript of Design Patterns Summer Course 2009-2010 - Session#4

Lecture #4Ahmed Safwat

Muhamad HeshamAbdelrahman Al-Ogail

What about Singleton? Call for a new requirement. First try implementation. Meet today’s pattern. Second try implementation. Common uses. Project Description. What’s after all of this?

What have we didtill now?

You: Dad, I need pocket money.

Dad: *^^%^&@&**&^#&*%&*#%

Away

Available

Busy

busy

sign in

Offline

away

away

available

busy

available

All states are connected

to offline via sign out

Out of Pepsi

Pepsi Sold

No Money

Has Money

insert

money

eject

money

pepsi > 0

pepsi = 0

order pepsi

Running Idle

reach cliff

after a while

I want the enemy turn crazy when you collect a gem.

If you touch the enemy while it is crazy, you die and it turns idle again.

Double crazy enemy speed by 4 times once.

Running Idle

reach cliff

after a while

Crazy

gem

collectedgem

collected

player died

What do you think we need do this time ?

Violates Open Closed Princible.

Not object oriented. Further additions will

cause bugs. State transitions are

buried between if-else.

Exploring the pattern Let’s Google it!

Explaining the pattern Pattern class diagram

Pac-Man

Keyboard with Shift Key

Windows Live Mail (Offline/Online)

Pattern’s Challenge Try it yourself

Strategy/State conflict Challenge:

What are the differences between State and

Strategy Pattern?

What’s Next

State Pattern: Chapter 10 in Head First Strategy Pattern: Chapter 1 in Head First GoF: Behavioral Pattern Section Section: enhance way of drawing shapes

Further Reading

Questions??mhesham.fcis@gmail.com

Zikas_zak@hotmail.com