1. Lecture # 2
Ahmed Safwat
Abdelrahman Z. Al-Ogail
Muhamad Hesham
2. 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).
3. 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.
4. 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.
5. Our code smells bad!
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 modify
the level code.
15. Implementation Developing the pattern in C#
See how we develop a pattern!
16. Call for new requirement
Once the player die I want:
Enemies speed is reset.
Other gems change its color
to black.
17. 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.
18. 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
19. 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.
20. 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
21. 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
22. It is about times
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.
23. What’s Next Books to read
Head First – Design Patterns: Chapter # 2
GoF – Behavioral Patterns Section