How to develop high quality software? What are the key/fundamental principles for software design? This presentation shares key insights on developing high-quality software in industrial contexts. By attending this session, you’ll get a clear understanding of the key role that design principles play in developing software. Further, you’ll know three specific approaches on how to apply design principles in practice.
1. Three Ways to Apply Design
Principles in Practice
Ganesh Samarthyam
Consultant, Trainer, and Author
ganesh.samarthyam@gmail.com
www.designsmells.com
3. The city metaphor
Source: http://indiatransportportal.com/wp-content/
uploads/2012/04/Traffic-congestion1.jpg
“Cities grow, cities evolve, cities
have parts that simply die while
other parts flourish; each city has
to be renewed in order to meet the
needs of its populace… Software-
intensive systems are like that.
They grow, they evolve,
sometimes they wither away, and
sometimes they flourish…”
12. Real scenario #1
❖ How will you refactor such
that:
❖ A specific DES, AES, TDES,
… can be “plugged” at
runtime?
❖ Reuse these algorithms in
new contexts?
❖ Easily add support for new
algorithms in Encryption?
Next change:
smelly design
25. Open Closed Principle (OCP)
Bertrand Meyer
Software entities should be open for
extension, but closed for modification
26. Variation Encapsulation Principle (VEP)
Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides
Encapsulate the concept that varies
27. Fundamental principle: Encapsulation
The principle of encapsulation advocates separation of concerns and
information hiding through techniques such as hiding implementation
details of abstractions and hiding variations
31. Real scenario
❖ How will you refactor such
that:
❖ You don't have to “multiply-
out” sub-types? (i.e., avoid
“explosion of classes”)
❖ Add or remove
responsibilities (e.g.,
scrolling) at runtime?
Next change:
smelly design
32. How about this solution?
VisualComponent
+ Draw()
TextView
+ Draw()
ScrollDecortor BorderDecorator
+ Draw()
+ ScrollTo()
- ScrollPosition
+ Draw()
+ DrawBorder()
- borderWidth
Decorator
+ Draw() component->Draw()
Decorator::Draw()
DrawBorder()
Decorator::Draw()
ScrollTo()
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
33. At runtime (object diagram)
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
34. Can you identify the pattern?
VisualComponent
+ Draw()
TextView
+ Draw()
ScrollDecortor BorderDecorator
+ Draw()
+ ScrollTo()
- ScrollPosition
+ Draw()
+ DrawBorder()
- borderWidth
Decorator
+ Draw() component->Draw()
Decorator::Draw()
DrawBorder()
Decorator::Draw()
ScrollTo()
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
35. You’re right: Its Decorator pattern!
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
36. Identify pattern used in this code
LineNumberReader lnr =
new LineNumberReader(
new BufferedReader(
new FileReader(“./test.c")));
String str = null;
while((str = lnr.readLine()) != null)
System.out.println(lnr.getLineNumber() + ": " + str);
40. Composite pattern
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994