Upload
muhamad-hesham
View
213
Download
0
Tags:
Embed Size (px)
Citation preview
Lecture # 2Ahmed Safwat
Abdelrahman Z. Al-OgailMuhamad Hesham
Call for a new requirement. First try for implementation. Bad smell code. Meet observer pattern. Pattern class diagram. Second try for implementation.(developing
pattern in C#). Common uses. What’s next? (Further reading).
Call for new requirement
Once the player collects a gem I want:
Enemy increases its speed.
Other gems change its color to a random color.
First try for implementation
1. We need find the place in code where
the gem is tested for being collected.
2. We need modify enemy speed.
3. We need modify gem color.
What bad things we did ?
1. We expose private
members to the public.
2. We are dependant on
certain members.
3. Each time we need modifythe level code.
Our code smells bad!
Real life example
Do you know how news paper subscribtion work ?
SubscribersNot notified
Publisher
Publisher + Subscriber
Subscribers
Subscribe
Publisher
Publisher + Subscriber
Subscribers
Publisher
Publisher + Subscriber
Subscribers
I am not interested anymore
Publisher
Publisher + Subscriber
SubscribersNot notified
Publisher
Publisher + Subscriber
Discovering Pattern Let’s Google it!
Explaining the Pattern See how it’s easy!
Class Diagram Source: GoF’s Book
Implementation Developing the pattern in C#
See how we develop a pattern!
Call for new requirement
Once the player die I want:
Enemies speed is reset.
Other gems change its color to black.
Just pattern it
1. We need find the place in code where
the gem is player is tested for being dead.
2. We need reset enemy speed.
3. We need modify color gem with
black.
Common Uses Source: GoF’s Book
Spreadsheets, Bar Graph and Pie Graph presentations of the same data.
Chat Windows in IMs.
RSS and News-feed.
In Smalltalk programming language MVC
Model: subject
View: observers
What’s Next? Wait a minute! What about the rest
Patterns explanation in GoF
Pattern Name and Classification: A descriptive and unique name that helps in identifying and referring to the pattern
Intent: A description of the goal behind the pattern and the reason for using it.
Also Known As: Other names for the pattern
Motivation (Forces): A scenario consisting of a problem and a context in which this pattern can be used.
What’s Next? Wait a minute! What about the rest
Patterns explanation in GoF
Consequences: A description of the results, side effects, and trade offs caused by using the pattern.
Sample Code: An illustration of how the pattern can be used in a programming language
Known Uses: Examples of real usages of the pattern.
Related Patterns: Other patterns that have some relationship with the pattern; discussion of the differences between the pattern and similar patterns
What’s Next? Not Covered points
Design Advantages of using this pattern:
Objects are loosely coupled.
Adding new observers at any time without effort.
Changes in subject or observer don’t effect the other
How they attended Lessons? How they managed their time?
Reading while eating & walking
Eating Ka`ak
Results:
Bagdad Library
Saheb Abn Abbad`s Library
▪ Lon Gorand talking about his books 400 Hajri.
It is about times
What’s Next Books to read
Head First – Design Patterns: Chapter # 2
GoF – Behavioral Patterns Section