Design Patterns - An Introduction

Slides:



Advertisements
Similar presentations
Welcome to. Who am I? A better way to code Design Patterns ???  What are design patterns?  How many are there?  How do I use them?  When do I use.
Advertisements

COMPSCI 105 S Principles of Computer Science 12 Abstract Data Type.
 Recent researches show that predicative programming can be used to specify OO concepts including classes, objects, interfaces, methods, single and multiple.
Design Patterns CS is not simply about programming
James Tam Introduction To Design Patterns You will learn about design techniques that have been successfully applied to different scenarios.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Todd Snyder Development Team Lead Infragistics Experience Design Group.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
MiniDraw Introducing a Framework... and a few patterns.
February 23, 2009Observer Pattern, OOA&D, Rubal Gupta, CSPP, Winter ‘09 Observer Pattern Defines a “one-to-many” dependency between objects so that when.
Software Architecture and Design BITS C461/IS C341 Software Engineering First Semester Aditya P. Mathur Department of Computer Science Purdue.
Design Engineering 1. Analysis  Design 2 Characteristics of good design 3 The design must implement all of the explicit requirements contained in the.
Engineered for Tomorrow Unit:8-Idioms Engineered for Tomorrow sharmila V Dept of CSE.
12. DISTRIBUTED WEB-BASED SYSTEMS Nov SUSMITHA KOTA KRANTHI KOYA LIANG YI.
Engineering, 7th edition. Chapter 8 Slide 1 System models.
Software Reuse. Objectives l To explain the benefits of software reuse and some reuse problems l To discuss several different ways to implement software.
Engineering Quality Software Week02 J.N.Kotuba1 SYST Engineering Quality Software.
Introduction To Design Patterns
Design Patterns Source: “Design Patterns”, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides And Created.
GRASP – Designing Objects with Responsibilities
Design Patterns: MORE Examples
CompSci 280 S Introduction to Software Development
Object-oriented and Structured System Models
Chapter 5 – Design and Implementation
Chapter 7 – Object-Oriented Design
The Object-Oriented Thought Process Chapter 15
Slide design: Dr. Mark L. Hornick
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
MPCS – Advanced java Programming
Introduction to Design Patterns
Design Patterns Lecture part 2.
Physical Data Model – step-by-step instructions and template
A Brief Introduction to Design Patterns
Introduction to Design Patterns
Complexity Time: 2 Hours.
Software Reuse ©Ian Sommerville 2006.
Observer Design Pattern
Introduction with a few design patterns
OO Methodology OO Architecture.
Magento Technical Guidelines Eugene Shakhsuvarov, Software Magento
CHAPTER 2 CREATING AN ARCHITECTURAL DESIGN.
Design and Maintenance of Web Applications in J2EE
Enterprise Data Model Enterprise Architecture approach Insights on application for through-life collaboration 2018 – E. Jesson.
Design Patterns - A few examples
Advanced Programming Behnam Hatami Fall 2017.
Web Programming Language
Chapter 5 Designing the Architecture Shari L. Pfleeger Joanne M. Atlee
Introduction to Design Patterns Part 1
Model-View-Controller Patterns and Frameworks
Patterns.
Observer Pattern 1.
Software Architecture
Exploring the Power of EPDM Tasks - Working with and Developing Tasks in EPDM By: Marc Young XLM Solutions
Object oriented analysis and design
Starting Design: Logical Architecture and UML Package Diagrams
Chapter 5 Architectural Design.
An Introduction to Software Architecture
ISpec: A Compositional Approach to Interface Specification
Lesson 5: More on Creational Patterns
Design Patterns Lecture part 1.
OBJECT ARCHITECTURE DESIGN
Engineering Quality Software
Software Modelling and Design
Model, View, Controller design pattern
Chapter 8, Design Patterns Introduction
Chapter 6: Architectural Design
Software Engineering and Architecture
Presentation transcript:

Design Patterns - An Introduction Today’s Agenda 2/25/2019 BITS, Pilani. Sundar B.

Today’s Topics Design Templates Patterns - Motivating Example Principles, Implements / Processes, Templates Relevance to Software Templates Context Granularity Patterns - Motivating Example MVC Observer BITS, Pilani. Sundar B. 2/25/2019

Design - Principles Consider designing an “entrance to a building” Physical entity could be a door, a change in elevation, or through a courtyard. Principle: Transition of the environment – i.e. crossing the boundary - should be a sensory experience. BITS, Pilani. Sundar B. 2/25/2019

Design – Principles [2] Consider creating an opening scene for a movie An event or an activity that includes principal actors (hero, heroine, villain) Principle: Establish the “embodiment” – i.e. physical realization - of a theme. BITS, Pilani. Sundar B. 2/25/2019

Design - Implements/Processes Building Entrance Drawing of the front view Clay model of courtyard Movie Opening A car chase A confrontation between adversaries BITS, Pilani. Sundar B. 2/25/2019

Design - Templates Building Entrance Movie Opening Library: “High elevation” entrances Airport: Wide entrance with multiple doors Church: “oak doors with stained glass decorations” Movie Opening Villain has a weapons factory – hero destroys it: “James Bond” template Young kid gets separated from mother/brother: -Bollywood variant of the “Karna” template. BITS, Pilani. Sundar B. 2/25/2019

Software Design – Principles and Implements / Processes Basic: Separation of Concerns Implied: Modularity and Re-use. Implements / Processes: Top-down design Language constructs for data abstraction User Interface Toolkit BITS, Pilani. Sundar B. 2/25/2019

Software Design – Templates Example 1: Iterate over array elements in C or Java for ( j=0; j<N; j++) … A[j] … Example 2: Use indirection to enable sharing. int *m, *n; … // Assignments to m, n swap(m, n); // Code in swap may modify m,n BITS, Pilani. Sundar B. 2/25/2019

Software Design – Templates [2] Example 3: Store interfaces or type declarations in header files (of a C program) /*file SetOps.h */ Set setUnion(Set s1, Set s2); /*file Set.h */ typedef unsigned int Set; /*file SetOps.h */ Set setUnion(Set s1, Set s2) { return s1 | s2; }

Software Design – Templates [3] Example 4: Browser - Document Object Model Requirements: Elements may contain other elements e.g. Table may contain a Form or another Table; a Form contain a Table. etc. Parser should present a uniform interface for all elements to other modules (say rendering engine) … BITS, Pilani. Sundar B. 2/25/2019

Software Design – Templates [4] Example 4 (contd..) - Design: Element Text Formatter is-a Semantic Element is-a is-a 1..n composed of Anchor Layout Container Table is-a Form is-a

Software Design – Templates [5] Example 5: Sets or Collections – Operations Requirements: Operations may have to access each element of a set / collection Different implementations (with different pros and cons) are available for collections. Design: Provide a way to enumerate elements of a set. Operations use enumerator for accessing elems. BITS, Pilani. Sundar B. 2/25/2019

Software Design – Templates [6] Example 6: Design an online document publishing system for BITS Requirements: Authors submit documents online in different formats. Publishing system uses different markup languages for different displays. Documents have to spell-checked before being published. BITS, Pilani. Sundar B. 2/25/2019

Software Design – Templates [7] Example 6 (contd..) - Design: Word Doc. Generic Transducer XML PDF Doc. Spell Checker Device Transducer XML DeviceML DeviceML BITS Styler Display / Blaster DeviceStyle BITS, Pilani. Sundar B. 2/25/2019

Software Design – Templates [8] Example 6 (contd..) – Design: Modules are designed as input to output transducers. That is, they are filters! (recall Unix commands) Modules are not sharing any external data or other modules. So, they can be run concurrently (without explicit synchronization). That is, they can be piped! (recall Unix pipes) BITS, Pilani. Sundar B. 2/25/2019

Software Design – Templates [9] What are templates? They provide (generic) solutions – often for more than one instance of a problem. These solutions can be (contextually) reused with minor adaptations. Templates are contextual but generic solutions that are re-usable with minor adaptations. BITS, Pilani. Sundar B. 2/25/2019

Software Design – Templates [10] Observations: There are some differences among templates (even among the ones we studied today) Problem contexts are different: Low level design (close to coding) Medium level design High level design (close to architecture) Often leads to different granularities! BITS, Pilani. Sundar B. 2/25/2019

Software Design – Templates [11] Low level templates: Fine grained; Often no additional work required to use. Implementation (say language or OS) specific a.k.a IDIOMS Almost always work as advertised! Examples: 1 (Iteration & Arrays), -- Refer to Slide 8 2 (Sharing & Indirection) -- Refer to Slide 8 3 (Program Structuring in C) -- Refer to Slide 9 BITS, Pilani. Sundar B. 2/25/2019

Software Design – Templates [12] Medium level templates: Not so fine-grained; Adaptations often required for specific situation/problem. May lead to minor problems when mis-applied. a.k.a (DESIGN) PATTERNS Examples: 4 ( Browser – Composite Pattern) (Refer to Slide 11) 5 ( Set Enumeration – Iterator Pattern) (Refer to Slide 12) BITS, Pilani. Sundar B. 2/25/2019

Software Design – Templates [13] High level templates: Coarse-grained. Often require lot of customization and implementation to achieve desired result. Often Specific to problem domain. When mis-applied lead to disastrous results! a.k.a (ARCHITECTURAL) FRAMEWORKS Examples: 6 (Document Publishing – Pipe & Filter Architecture) BITS, Pilani. Sundar B. 2/25/2019

((Software) Design) Patterns Definition: Contextual Design solutions of medium granularity that can be re-used in recurring design problems with minimal adaptation. Usage: Documentation of (Expert) Knowledge of Design solutions. Purpose: Communication and Persistence for Re-use. BITS, Pilani. Sundar B. 2/25/2019

((Software) Design) Patterns Why study patterns? “to organize implicit knowledge about how people solve recurring problems when they go about building things” – Christopher Alexander, (Architect by profession; Father of modern study of patterns) BITS, Pilani. Sundar B. 2/25/2019

Patterns Software context: Most of the work originated in SmallTalk community. SmallTalk was a programming language: Object Oriented Meant for rapid prototyping Came with (what are known today as) IDE and API IDE elements were in SmallTalk! (Concrete) Precursor to modeling, frameworks and patterns! BITS, Pilani. Sundar B. 2/25/2019

Patterns – MVC framework SmallTalk’s user interface framework Model - refers to data model View – refers to external views or presentation of data. Controller – refers to module relating reactions of view or presentation to changes in data. BITS, Pilani. Sundar B. 2/25/2019

MVC Framework [2] Need to separate presentational aspects with the data, i.e. separate views and data. Classes defining application data and presentation can be reused. Change in one view automatically reflected in other views. Also, change in the application data is reflected in all views. Defines one-to-many dependency amongst objects so that when one object changes its state, all its dependents are notified. BITS, Pilani. Sundar B. 2/25/2019

MVC Framework [3] A D C B Y 10 40 30 20 X 15 35 35 15 Z 10 40 30 20 Relative Percentages Y 10 40 30 20 X 15 35 35 15 Z 10 40 30 20 A B C D A B C D A=10% B=40% C=30% D=20% Application data Change notification Requests, modifications BITS, Pilani. Sundar B. 2/25/2019

Observer Pattern Model – View paradigm can be generalized: A view is an observer A model is an subject that is observed. Referred to as the observer pattern. BITS, Pilani. Sundar B. 2/25/2019

Observer Pattern [2] Subject observers Observer attach (Observer) detach (Observer) Notify () observers Observer Update() For all x in observers{ x  Update(); } Concrete Observer Update() observerState subject Concrete Subject GetState() SetState() subjectState observerState= subject  getState(); BITS, Pilani. Sundar B. 2/25/2019