1 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Introduction to Design Patterns.

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

 Recent researches show that predicative programming can be used to specify OO concepts including classes, objects, interfaces, methods, single and multiple.
CS590L - Lecture 6 1 CS590L Distributed Component Architecture References: - E. Gamma, R. Helm, R. Johnson, J. Vlissides, Design Patterns: Elements of.
By Xiangzhe Li Thanh Nguyen.  Components and connectors are composed in a specific way in a given system’s architecture to accomplish that system’s objective.
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
Dept. of Computer Engineering, Amirkabir University of Tech. 1 Design Patterns Dr. Noorhosseini Introduction.
Design Patterns CS is not simply about programming
Copyright © Active Frameworks, Inc.. - All Rights Reserved - V2.0 Introduction - Page L1-1 PS95&96-MEF-L1-1 Dr. M.E. Fayad Creationa l Paradigm.
Ralph Johnson - University of Illinois1 Patterns: What They Are, and How to Write Them Ralph Johnson University of Illinois at Urbana-Champaign
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Design Patterns Discussion of pages: xi-11 Sections: Preface, Forward, Chapter
R R R Design Patterns. R R R Acknowledgements Materials based on a number of sources –D. Levine and D. Schmidt –R. Helm –Gamma et al.
Design Patterns.
Design Patterns OOD. Course topics Design Principles UML –Class Diagrams –Sequence Diagrams Design Patterns C#,.NET (all the course examples) Design Principles.
1/19 Component Design On-demand Learning Series Software Engineering of Web Application - Principles of Good Component Design Hunan University, Software.
Design Patterns: Introduction. Creational Design Patterns General and reusable solutions to common problems in software design Software University
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
Chapter Five An Introduction to Design Patterns Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Powerpoint Templates Page 1 Powerpoint Templates What is Design Patterns ? by Indriati Teknik Informatika – UB.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
Patterns and Reuse. Patterns Reuse of Analysis and Design.
Object-Oriented Design Principles and Patterns. © 2005, James R. Vallino2 How Do You Design? What principles guide you when you create a design? What.
1 Introduction to Software Engineering Lecture 1.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
GRASP: Designing Objects with Responsibilities
DESIGN PATTERNS CSC532 Adv. Topics in Software Engineering Shirin A. Lakhani.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
CSE 403 Lecture 14 Design Patterns. Today’s educational objective Understand the basics of design patterns Be able to distinguish them from design approaches.
Design Patterns Introduction General and reusable solutions to common problems in software design SoftUni Team Software University
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
ECE450S – Software Engineering II
1 A Brief Introduction to Design Patterns Based on materials from Doug Schmidt 1.
CSC 480 Software Engineering Design With Patterns.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
CSE 332: Design Patterns Review: Design Pattern Structure A design pattern has a name –So when someone says “Adapter” you know what they mean –So you can.
Advanced Object-Oriented Design Patterns and Architectures Part One COEN396A John Xiao
Design Patterns: Elements of Reusable Object- Orientated Software Gamma, Helm, Johnson, Vlissides Presented By: David Williams.
Design Patterns Introduction
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 31. Review Creational Design Patterns – Singleton Pattern – Builder Pattern.
Design Patterns Introduction “Patterns are discovered, not invented” Richard Helm.
Design Patterns in Context ©SoftMoore ConsultingSlide 1.
Design Patterns for Games Proceedings of the 33 rd SIGCSE technical symposium on Computer Science Education Melisa Tyira SE510.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
From Use Cases to Implementation 1. Structural and Behavioral Aspects of Collaborations  Two aspects of Collaborations Structural – specifies the static.
Class Relationships Lecture Oo08 Polymorphism. References n Booch, et al, The Unified Modeling Language User Guide, Chapt 10 p.125 n Fowler & Scott, UML.
From Use Cases to Implementation 1. Mapping Requirements Directly to Design and Code  For many, if not most, of our requirements it is relatively easy.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
GRASP – Designing Objects with Responsibilities
Design Patterns: MORE Examples
Software Design Patterns
Introduction to Design Patterns
A Brief Introduction to Design Patterns
Introduction to Design Patterns
Design Patterns Introduction
Design Patterns.
Informatics 122 Software Design II
Patterns.
Introduction to Design Patterns
Informatics 122 Software Design II
Software Design Lecture : 27.
Presentation transcript:

1 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Introduction to Design Patterns

2 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Patterns of Learning  Successful solutions to many areas of human endeavor are deeply rooted in patterns  important goal of education is transmitting patterns of learning from generation to generation  Discuss next patterns used for chess learning  Learning to develop good software is similar to learning to play good chess  though consequences of failure are far less dramatic in chess playing!

3 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Becoming a Chess Master  Learn the rules and physical requirements  e.g. pieces, legal movements, chess board geometry and orientation.  Learn the principles  e.g. relative value of certain pieces, strategic values of center squares, power of a threat etc.  To become a master, one must study the games of other masters  these games contain patterns that must be understood, memorized and applied repeatedly  There are hundreds of such patterns

4 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Becoming a Software Design Master  First learn the rules  e.g. the algorithms, data structures and languages of software  Then learn the principles  e.g. principles that govern different programming paradigms  structured, modular, object-oriented, etc  To truly master software design, one must study the design of other masters  these designs contain patterns that must be understood, memorized and applied repeatedly  There are hundreds of these patterns

5 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 What is a Pattern ? Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice C. Alexander, “The Timeless Way of Building”, 1979

6 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Alexander's View of a Pattern  Three part rule that expresses a relation between a certain context, a problem and a solution.  Element of the world – a relationship between  a context  a system of forces that occur repeatedly in the context  a spatial configuration which allow forces to resolve themselves  Element of language – an instruction  describes how the spatial configuration can be repeatedly used  to resolve the given system of forces  wherever the context makes it relevant  The “thing – process” dualism  a thing that happens in the world  a process (rule) which will generate that thing

7 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Why Use Patterns ?  An additional layer of abstraction  separate things that change from things that stay the same  distilling out common factors between a family of similar problems  similar to design  Insightful and clever way to solve a particular class of problems  most general and flexible solution Patterns help you learn from other’s successes, instead of your own failures Mark Johnson (cited by B. Eckel)

8 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Design Patterns  Design patterns represent solutions to problems that arise when developing software within a particular context  Patterns = Problem/Solution pair in Context  Capture static and dynamic structure and collaboration among key participants in software designs  key participant – major abstraction that occur in a design problem  useful for articulating the how and why to solve non-functional forces.  Facilitate reuse of successful software architectures and design  i.e. the “design of masters”… ;)

9 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Example: Data-Views Consistency Problem

10 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 The Observer Pattern  Intent  Define a one-to-many dependency between objects so that when one object changes state, all its dependencies are notified and updated automatically  Forces  There may be many observers  Each observer may react differently to the same notification  The data-source (subject) should be as decoupled as possible from the observer  to allow observers to change independently of the subject

11 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Structure of the Observer Pattern

12 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Collaboration in the Observer Pattern

13 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 What Makes it a Pattern ? A pattern must... ...solve a problem  i.e. it must be useful ...have a context  it must describe where the solution can be used ...recur  must be relevant in other situations ... teach  provide sufficient understanding to tailor the solution ... have a name  referred consistently

14 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 GoF Form of a Design Pattern Pattern name and classification Intent what does pattern do Also known as other known names of pattern (if any) Motivation the design problem Applicability situations where pattern can be applied Structure a graphical representation of classes in the pattern Participants the classes/objects participating and their responsibilities Collaborations of the participants to carry out responsibilities

15 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 GoF Form of a Design Pattern (contd.) Consequences trade-offs, concerns Implementation hints, techniques Sample code code fragment showing possible implementation Known uses patterns found in real systems Related patterns closely related patterns

16 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Algorithmic Form of Patterns IF you find yourself in CONTEXT for example EXAMPLES, with PROBLEM, entailing FORCES THEN for some REASONS, apply DESIGN FORM AND/OR RULE to construct SOLUTION leading to NEW CONTEXT and OTHER PATTERNS

17 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Key Mechanisms in Design Patterns

18 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Class vs. Interface Inheritance  Class – defines an implementation  Type – defines only the interface  the set of requests that an object can respond to  Relation between Class and Type  the class implies the type  On class, many types. Many classes, same type  Clas Inheritance  one implementation in terms of another  Type Inheritance  when an object can be used in place of another

19 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 GoF Design Principle no. 1  Use interfaces to define common interfaces  and/or abstract classes in C++  Declare variables to be instances of the abstract class  not instances of particular classes  Use Creational patterns  to associate interfaces with implementations Program to an interface, not an implementation Benefits  Greatly reduces the implementation dependencies  Client objects remain unaware of the classes that implement the objects they use.  Clients know only about the abstract classes (or interfaces) that define the interface.

20 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Class Inheritance vs. Composition  Mechanisms of reuse  White-box vs. Black-box  Class Inheritance  easy to use; easy to modify  implementation being reused;  language-supported  static bound  can't change at run-time;  mixture of physical data representation  breaks encapsulation  change in parent  change in subclass  Object Composition  objects are accessed solely through their interfaces  no break of encapsulation  any object can be replaced by another at runtime  as long as they are the same type

21 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Design Principle no. 2 Favor composition over class inheritance  Keeps classes focused on one task  Inheritance and Composition Work Together!  ideally no need to create new components to achieve reuse  this is rarely the case!  reuse by inheritance makes it easier to make new components  modifying old components  Tendency to overuse inheritance as code-reuse technique  Designs – more reusable by depending more on object composition

22 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Classification of Design Patterns  Creational Patterns  deal with initializing and configuring classes and objects  how am I going to create my objects?  Structural Patterns  deal with decoupling the interface and implementation of classes and objects  how classes and objects are composed to build larger structures  Behavioral Patterns  deal with dynamic interactions among societies of classes and objects  how to manage complex control flows (communications)

23 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Design Pattern Catalog - GoF

24 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Benefits of Design Patterns  Inspiration  patterns don't provide solutions, they inspire solutions  Patterns explicitly capture expert knowledge and design tradeoffs and make this expertise widely available  ease the transition to object-oriented technology  Patterns improve developer communication  pattern names form a vocabulary  Help document the architecture of a system  enhance understanding  Design patterns enable large-scale reuse of software architectures

25 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Drawbacks of Design Patterns  Patterns do not lead to direct code reuse  Patterns are deceptively simple  Teams may suffer from patterns overload  Integrating patterns into a software development process is a human-intensive activity