Your SlideShare is downloading. ×
Design Patterns
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Design Patterns

2,444
views

Published on

This is a part of my series of presentations on C++ and Design Pattern. This is still being developed.

This is a part of my series of presentations on C++ and Design Pattern. This is still being developed.

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,444
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
83
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Cultural-Revolution (1966-76) excesses exposed on Mao's death (1976)
  • Transcript

    • 1. February 28, 2009 Design Pattern Dr. Partha Pratim Das Interra Systems (India) Pvt. Ltd. Abstractions in OOD Current Practices in Object Oriented Software Development Meghnad Saha Institute of Technology
    • 2. Agenda
      • Design Patterns
        • Patterns Everywhere
        • Fundamentals
        • Sample Pattern Overview
    • 3. Pattern’s Everywhere Quest in Human Endeavor
    • 4. Pattern’s Everywhere in Life
          • Summer, Winter, Autumn, Spring:
        • Climatic Pattern
          • New Moon, Full Moon:
        • Lunar Pattern
          • Iron Filings in a Magnetic Fields:
        • Magnetic Pattern
      • Patterns in Nature
    • 5. Pattern’s Everywhere in Life
          • Bhairavi, Malkosh, Hansadhwani:
        • Musical Pattern
          • Sonnet:
        • Poetic Pattern
          • Bibi #1, Hero #1, Jodi #1, Premi #1:
        • Bollywood Pattern
          • Hesh toric Win, The Damned, Grave end to Mutiny:
        • Media Pattern
          • Simple, Complex, Compound Sentences:
        • Grammatical Pattern
      • Patterns in Art / Humanities
    • 6. Pattern’s Everywhere in Life
          • 4-3-3, 5-2-3, 10:
        • Soccer Pattern
          • Castling:
        • Chess Pattern
      • Patterns in Sport
    • 7. Pattern’s Everywhere in Life
          • BTK, Stone Man:
        • Serial Killer Pattern
          • 9/11, 7/11, 26/11:
        • Terror Pattern
          • Mughal, Gandhi:
        • Dynastic Pattern
      • Patterns in Crime / Politics
    • 8. Pattern’s Everywhere in Life
          • Baluchari, Benarasi, Pachhampalli:
        • Silk Pattern
          • Palace, House, Apartment, Condo:
        • Housing Pattern
          • Recipe:
        • Cooking Pattern
          • Times New Roman, Arial, Verdana, Tahoma:
        • Typesetting Pattern
      • Patterns in Construction
    • 9. Pattern’s Everywhere in Life
          • Jiang Qing, Zhang Chunqiao, Yao Wenyuan, Wang Hongwen
            • Cultural-Revolution excesses exposed on Mao's death
          • Wang Dongxing, Wu De, Ji Dengkui, Chen Xilian
            • Hua Guofeng's clique; Crushed in 1980 by Deng Xiaoping
        • Corrupt Collusion Pattern
          • Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides
            • GoF Book on Pattern
        • Creative Consortium Pattern
      • Patterns in Collaboration
    • 10. Pattern’s Everywhere in Life
          • Semi-Group, Monoid, Group, Abelian Group:
        • Algebraic Pattern
          • Unconditional Branch, Conditional Branch, Definite Loop, Indefinite Loop, Recursion:
        • Programming Pattern
          • Divide-and-Conquer, Greedy, Dynamic Programming, Branch-and-Bound:
        • Algorithmic Pattern
          • Factory, Iterator, Visitor, Singleton:
        • Design Pattern
      • Patterns in Computation
    • 11. Pattern Pioneers Kurt Godel (1906-1978) Austrian-American Logician Who is he? This sentence is false
    • 12. Pattern Pioneers Who is he? Champion of Graphic Patterns
    • 13. Pattern Pioneers Maurits Cornelis Escher (1898-1972) Dutch Graphic Artist
    • 14. Pattern Pioneers Johann Sebastian Bach (1685-1750) German Composer & Organist Who is he?
    • 15. Pattern Pioneers Robert James Fisher (1943-2008) US Chess World Champ Who is he?
    • 16. Pattern Pioneers Who is he? Donald Ervin Knuth (1938-) Father of Analysis of Algorithms
    • 17. Pattern Pioneers There is one timeless way of building. It is a thousand years old, and the same today as it has ever been. The great traditional buildings of the past, the villages and tents and temples in which man feels at home, have always been made by people who were very close to the center of this way. It is not possible to make great buildings, or great towns, beautiful places, places where you feel yourself, places where you feel alive, except by following this way. And, as you will see, this way will lead anyone who looks for it to buildings which are themselves as ancient in their form, as the trees and hills, and as our faces are. Who is he? Christopher Alexander (1936-) Architect – The Pattern Language
    • 18. Patterns in Life: Take Back
      • Patterns Pervade
      • Patterns Drive Research
      • Patterns are the greatest exploits for Design
    • 19. Design Patterns Search of Similarities in OOD
    • 20. What is a Design Pattern?
      • A Design Pattern
        • describes a problem
          • Occurring over and over again (in software engineering)
        • describes the solution
          • Sufficiently generic
          • Applicable in a wide variety of contexts.
      Recurring Solution to a Recurring Problem
    • 21. Essential Elements of a Design Pattern
      • Pattern Name: Descriptor for a design problem, its solutions, and their consequences.
      • Problem: Where to apply the pattern and its associated context.
      • Solution: Elements that make up the design, their relationships, responsibilities, and collaborations.
      • Consequences: Results and trade-offs in applying the pattern.
    • 22. Example Pattern
      • Pattern Name
        • Iterator
      • Problem
        • How to serve Patients at a Doctor’s Clinic
      • Solution
        • Front-desk manages the order for patients to be called
          • By Appointment
          • By Order of Arrival
          • By Extending Gratitude
          • By Exception
      • Consequences
        • Patient Satisfaction
        • Clinic’s Efficiency
        • Doctor’s Productivity
    • 23. Describing a Design Pattern
      • Pattern Name and Classification
        • The pattern's name conveys the essence of the pattern succinctly.
      • Intent
        • A short statement on:
          • What does the design pattern do?
          • What is its rationale and intent?
          • What particular design issue or problem does it address?
      • Also Known As
        • Other well-known names for the pattern.
    • 24. Describing a Design Pattern
      • Motivation
        • A scenario that illustrates a design problem and how the class and object structures in the pattern solve the problem.
      • Applicability
        • What are the situations in which the design pattern can be applied?
        • What are examples of poor designs that the pattern can address?
        • How can you recognize these situations?
    • 25. Describing a Design Pattern
      • Structure
        • A graphical representation of the classes in the pattern using a notation based on the Object Modeling Technique (OMT) – specifically UML.
      • Participants
        • The classes and/or objects participating in the design pattern and their responsibilities.
      • Collaborations
        • How the participants collaborate to carry out their responsibilities?
    • 26. Describing a Design Pattern
      • Consequences
        • How does the pattern support its objectives?
        • What are the trade-offs and results of using the pattern?
        • What aspect of system structure does can be varied independently?
      • Implementation
        • What pitfalls, hints, or techniques should you be aware of when implementing the pattern?
        • Are there language-specific issues?
    • 27. Describing a Design Pattern
      • Sample Code
        • Code fragments to implement the pattern in specific language (C++ or C# or Java).
      • Known Uses
        • Examples of the pattern found in real systems.
      • Related Patterns
        • What design patterns are closely related to this one?
        • What are the important differences?
        • With which other patterns should this one be used?
    • 28. Iterator Pattern
      • Pattern Name and Classification:
        • Iterator
        • Behavioral
      • Intent
        • Provide a way to access
        • the elements
        • of an aggregate object (container)
        • sequentially
        • without exposing its underlying representation.
      • CONTAINERS
      • Array
      • Vector
      • List
      • Stack
      • Queue
      • Tree
      • SEQUENTIAL
      • Forward
      • Backward
      • Bidirectional
      • Random
      • ACCESS
      • Read
      • Write
      • Read-Write
    • 29. Iterator Pattern
      • Also Known As
        • Cursor
      • Motivation
        • An aggregate object (list) should have a way to access its elements without exposing its internal structure.
        • There is a need to traverse the list in different ways, depending on a specific task.
        • Multiple traversals may be pending on the same list.
        • The key idea in this pattern is to take the responsibility for access and traversal out of the list object and put it into an iterator object.
    • 30. Iterator Pattern
      • Motivation
    • 31. Iterator Pattern
      • Motivation
    • 32. Iterator Pattern
      • Applicability
        • to access an aggregate object's contents without exposing its internal representation.
        • to support multiple traversals of aggregate objects.
        • to provide a uniform interface for traversing different aggregate structures (that is, to support polymorphic iteration).
    • 33. Iterator Pattern
      • Structure
    • 34. Iterator Pattern
      • Participants
        • Iterator
          • defines an interface for accessing and traversing elements.
        • ConcreteIterator
          • implements the Iterator interface.
          • keeps track of the current position in the traversal of the aggregate.
        • Aggregate
          • defines an interface for creating an Iterator object.
        • ConcreteAggregate
          • implements the Iterator creation interface to return an instance of the proper ConcreteIterator.
    • 35. Iterator Pattern
      • Collaborations
        • A ConcreteIterator keeps track of the current object in the aggregate and can compute the succeeding object in the traversal.
      • Consequences
        • It supports variations in the traversal of an aggregate.
        • Iterators simplify the Aggregate interface.
        • More than one traversal can be pending on an aggregate.
    • 36. Iterator Pattern
      • Implementation
        • Who controls the iteration?
          • External Iteration
          • Internal Iteration
        • Who defines the traversal algorithm?
        • How robust is the iterator?
          • What happens if items are inserted / deleted?
        • Additional Iterator operations
        • Using polymorphic iterators in C++.
          • allocated dynamically by a factory method
          • the client is responsible for deleting them
        • Iterators may have privileged access
          • friend class
        • Iterators for composites
        • Null iterators
    • 37. Iterator Pattern
      • Sample Code – Follows in the next few slides.
    • 38. Iterator Pattern
      • template <class Item>
      • class List {
      • public:
      • List(long size = DEFAULT_LIST_CAPACITY);
      • long Count() const;
      • Item& Get(long index) const;
      • // ...
      • };
    • 39. Iterator Pattern
      • template <class Item>
      • class Iterator {
      • public:
      • virtual void First() = 0;
      • virtual void Next() = 0;
      • virtual bool IsDone() const = 0;
      • virtual Item CurrentItem() const = 0;
      • protected:
      • Iterator();
      • };
    • 40. Iterator Pattern
      • template <class Item>
      • class ListIterator : public Iterator<Item> {
      • public:
      • ListIterator(const List<Item>* aList);
      • virtual void First();
      • virtual void Next();
      • virtual bool IsDone() const;
      • virtual Item CurrentItem() const;
      • private:
      • const List<Item>* _list;
      • long _current;
      • };
    • 41. Iterator Pattern
      • template <class Item>
      • ListIterator<Item>::ListIterator (
      • const List<Item>* aList
      • ) : _list(aList), _current(0) {
      • }
      • template <class Item>
      • void ListIterator<Item>::First () {
      • current = 0;
      • }
    • 42. Iterator Pattern
      • template <class Item>
      • void ListIterator<Item>::Next () {
      • current++;
      • }
      • template <class Item>
      • bool ListIterator<Item>::IsDone () const {
      • return _current >= _list->Count();
      • }
    • 43. Iterator Pattern
      • template <class Item>
      • Item ListIterator<Item>::CurrentItem () const {
      • if (IsDone()) {
      • throw IteratorOutOfBounds;
      • }
      • return _list->Get(_current);
      • }
    • 44. Iterator Pattern
      • void PrintEmployees (Iterator<Employee*>& i) {
      • for (i.First(); !i.IsDone(); i.Next()) {
      • i.CurrentItem()->Print();
      • }
      • }
      • List<Employee*>* employees;
      • // ...
      • ListIterator<Employee*> forward(employees);
      • ReverseListIterator<Employee*> backward(employees);
      • PrintEmployees(forward);
      • PrintEmployees(backward);
    • 45. Iterator Pattern
      • Known Uses
        • Iterators are common in object-oriented systems
      • Related Patterns
        • Composite:
          • Iterators are often applied to recursive structures such as Composites.
        • Factory Method:
          • Polymorphic iterators rely on factory methods to instantiate the appropriate Iterator subclass.
        • Memento:
          • Often used in conjunction with the Iterator pattern. An iterator can use a memento to capture the state of iteration. The iterator stores the memento internally.
    • 46. Catalogue of Design Patterns (GoF)
    • 47.  
    • 48. Visitor Pattern
      • Problem
        • Consultant in an Office
      • Solution
      • Consequences
    • 49. Factory Pattern
      • Problem
        • Bread Maker
      • Solution
      • Consequences
    • 50. Façade Pattern
      • Problem
        • Façade Website
      • Solution
      • Consequences
    • 51. Singleton Pattern
      • Problem:
        • Managing entities with one-instance-at-a-time
        • Office of the Principal of MSIT
        • Heart in a Human Body
        • cout, cin, cerr, clog …
      • Solution:
      • Consequences:
        • Synchronization needed for multi-threaded use
      • Note:
        • Closely related to Monostate Pattern
    • 52. Thank You
    • 53. Pattern’s Everywhere in Life
      • Pattern in Nature
        • Summer, Winter, Autumn: Climatic Pattern
        • New Moon, Full Moon: Lunar Pattern
        • Iron Filings in a Magnetic Fields: Magnetic Pattern
      • Patterns in Art/ Humanities
        • Bhairavi, Malkosh, Hansadhwani: Musical Pattern
        • Sonnet: Poetic Pattern
        • Bibi #1, Hero #1, Jodi #1, Premi #1: Bollywood Pattern
        • Hesh toric Win, The Damned: Media Pattern
        • Simple, Complex, Compound Sentences: Grammatical Pattern
      • Patterns in Sport
        • 4-3-3, 5-2-3, 10: Soccer Pattern
        • Castling: Chess Pattern
      • Patterns in Crime / Politics
        • BTK, Stone Man: Serial Killer Pattern
        • 9/11, 7/11, 26/11: Terror Pattern
        • Mughal, Gandhi: Dynastic Pattern
      • Patterns in Construction
        • Baluchari, Benarasi, Pachhampalli: Silk Pattern
        • Palace, House, Apartment, Condo: Housing Pattern
        • Recipe: Cooking Pattern
        • Times New Roman, Arial, Verdana, Tahoma: Typesetting Pattern
      • Patterns in Computation
        • Semi-Group, Monoid, Group, Abelian Group: Algebraic Pattern
        • Unconditional Branch, Conditional Branch, Definite Loop, Indefinite Loop, Recursion: Programming Pattern
        • Divide-and-Conquer, Greedy, Dynamic Programming, Branch-and-Bound: Algorithmic Patterny
        • Factory, Iterator, Visitor, Singleton: Design Pattern