24
Lecture #4 Ahmed Safwat Muhamad Hesham Abdelrahman Al-Ogail

Design Patterns Summer Course 2009-2010 - Session#4

Embed Size (px)

Citation preview

Page 1: Design Patterns Summer Course 2009-2010 - Session#4

Lecture #4Ahmed Safwat

Muhamad HeshamAbdelrahman Al-Ogail

Page 2: Design Patterns Summer Course 2009-2010 - Session#4

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?

Page 3: Design Patterns Summer Course 2009-2010 - Session#4

What have we didtill now?

Page 4: Design Patterns Summer Course 2009-2010 - Session#4

You: Dad, I need pocket money.

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

Page 5: Design Patterns Summer Course 2009-2010 - Session#4
Page 6: Design Patterns Summer Course 2009-2010 - Session#4
Page 7: Design Patterns Summer Course 2009-2010 - Session#4

Away

Available

Busy

busy

sign in

Offline

away

away

available

busy

available

All states are connected

to offline via sign out

Page 8: Design Patterns Summer Course 2009-2010 - Session#4
Page 9: Design Patterns Summer Course 2009-2010 - Session#4

Out of Pepsi

Pepsi Sold

No Money

Has Money

insert

money

eject

money

pepsi > 0

pepsi = 0

order pepsi

Page 10: Design Patterns Summer Course 2009-2010 - Session#4

Running Idle

reach cliff

after a while

Page 11: Design Patterns Summer Course 2009-2010 - Session#4

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.

Page 12: Design Patterns Summer Course 2009-2010 - Session#4

Running Idle

reach cliff

after a while

Crazy

gem

collectedgem

collected

player died

Page 13: Design Patterns Summer Course 2009-2010 - Session#4

What do you think we need do this time ?

Page 14: Design Patterns Summer Course 2009-2010 - Session#4

Violates Open Closed Princible.

Not object oriented. Further additions will

cause bugs. State transitions are

buried between if-else.

Page 15: Design Patterns Summer Course 2009-2010 - Session#4

Exploring the pattern Let’s Google it!

Page 16: Design Patterns Summer Course 2009-2010 - Session#4
Page 17: Design Patterns Summer Course 2009-2010 - Session#4

Explaining the pattern Pattern class diagram

Page 18: Design Patterns Summer Course 2009-2010 - Session#4
Page 19: Design Patterns Summer Course 2009-2010 - Session#4

Pac-Man

Page 20: Design Patterns Summer Course 2009-2010 - Session#4

Keyboard with Shift Key

Page 21: Design Patterns Summer Course 2009-2010 - Session#4

Windows Live Mail (Offline/Online)

Page 22: Design Patterns Summer Course 2009-2010 - Session#4

Pattern’s Challenge Try it yourself

Strategy/State conflict Challenge:

What are the differences between State and

Strategy Pattern?

Page 23: Design Patterns Summer Course 2009-2010 - Session#4

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