SENG 422 Lab 2 Design Patterns Time: ELW B220 from (4:00 - 6:50) every Tuesday TA: Philip Baback Alipour Ph.D. Candidate in Electrical, Computer Engineering.

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

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.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
 Recent researches show that predicative programming can be used to specify OO concepts including classes, objects, interfaces, methods, single and multiple.
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
BehavioralCmpE196G1 Behavioral Patterns Chain of Responsibility (requests through a chain of candidates) Command (encapsulates a request) Interpreter (grammar.
Design Patterns CS is not simply about programming
Façade Pattern Jeff Schott CS590L Spring What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance.
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
Dept. of Computer Engineering, Amir-Kabir University 1 Design Patterns Dr. Noorhosseini Lecture 2.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Design Patterns.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
An Introduction to Software Architecture
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
Case Studies on Design Patterns Design Refinements Examples.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Facade Introduction. Intent Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
ECE450S – Software Engineering II
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Behavioural Design Patterns Quote du jour: ECE450S – Software Engineering II I have not failed. I've just found 10,000 ways that won't work. - Thomas Edison.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Design Patterns By Mareck Kortylevitch and Piotreck Ratchinsky.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
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.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Manali Joshi1 The Observer Design Pattern Presented By: Manali Joshi.
Behavioral Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
Design Patterns Introduction
Using Software Design Patterns Bill Anderson. About me Fox developer since 1987 Fox developer since 1987 Program Director, Los Angeles Visual Foxpro Developers.
Java Design Patterns Java Design Patterns. What are design patterns? the best solution for a recurring problem a technique for making code more flexible.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CS 5150 Software Engineering Lecture 16 Program Design 3.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Programming with Patterns Jeremy Cronan Alliance Safety Council
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Design Patterns: MORE Examples
Software Design Refinement Using Design Patterns
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Introduction to Design Patterns
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
object oriented Principles of software design
Presented by Igor Ivković
Patterns.
Design Patterns Lecture part 1.
Informatics 122 Software Design II
Chapter 8, Design Patterns Introduction
Presented by Igor Ivković
Presentation transcript:

SENG 422 Lab 2 Design Patterns Time: ELW B220 from (4:00 - 6:50) every Tuesday TA: Philip Baback Alipour Ph.D. Candidate in Electrical, Computer Engineering and Quantum Physics, Dept. of Electrical and Computer Engineering, University of Victoria, CA   Office: ELW Room # A358

SENG 422 Lab 2 Design Patterns Design Patterns: A way to solve a problem in a context, given collected experience in a domain. Types: Idioms: provide a solution for specific programming issues in given language. Design patterns: provide solutions to commonly recurring design issues. Architectural patterns: provide templates for designing entire architectures.

Pattern Description A pattern can be described by using a three-part schema: Context: description of situations in which the problem arise. Problem: general description of the design issues that need to be solved by the pattern, and the driving forces or (risk, quality) factors behind these issues. Solution: the solution consists of two aspects: a static aspect that describes the structural components involved, a dynamic aspect that describes their run-time behaviour.

Pattern Description Pattern Name Context - Quality/Risk factors giving rise to design issue(s) Problem - Design issues Solution - Components/connectors (see, e.g., diagrams.org/component-diagrams.html ) diagrams.org/component-diagrams.html -Run-time behavior such as studying error occurrence, addressing them through exception handlers (see e.g.,

Example pattern - Singleton Singleton Context Control access to a class by controlling instantiation process. Problem An application contains a certain type of data that needs to be globally accessed and maintained. At the same time, this type of data is often unique in the system. How do you provide an accessible interface to a class, but control the number of instances within the system? Solutions The class itself is responsible for creating a single instance and providing Global access to that instance. Create a class that contains a static instance of the Singleton that is returned with a static method name getinstance(). Singleton - SingleInstance +GetInstance() SingleInstance: Singleton

Decorator Pattern Are you familiar with the Command Pattern? Let's suppose I have an interview this morning? I don't feel good, and I look horrible. Would I want to make someone else stand in? ie. Should I sub in another class? NO. I would decorate myself as follows: Shower, dress shoes, dress shirt, do my hair, breakfast, coffee etc. This is the essence of the decorator pattern. I decorate myself (the base) with other objects that would enhance my function.

EmployeeEvaluation - Example Let's say you’re the interviewer, and you want to evaluate me based on those things we mentioned above: Shirt, hair, shoes etc. We would create a base class for evaluation as follows:

EmployeeEvaluation - Example cont

9 Patterns Categories -Three categories of design patterns: creational, structural, and behavioral. Creational patterns: create instances of objects for your application Structural patterns: compose groups of objects into larger structures Behavioral patterns: define the communication and flow of control in a complex program.

10 Example of Creational Pattern - Factory pattern: provides a decision-making class that returns selectively one of several possible subclasses of an abstract base class. DrawingFactory getDrawing(): Drawing public class DrawingFactory { public Drawing getDrawing(int criteria) { if (criteria = 0) return new Triangle(); else return new Circle(); } Drawing draw() getDimension(): Dimension Circle Circle() Triangle Triangle() Benefits of factory pattern: - Code is made more flexible and reusable by the elimination of instantiation of application-specific classes - Code deals only with the interface of the Product class and can work with any ConcreteProduct class that supports this interface

11 Example of Structural Pattern Façade Pattern: -Is used to wrap a set of complex classes into a simpler enclosing interface. -Provides a unified and higher-level interface that makes a subsystem easier to use. Facade Client classes Subsystem classes

12 Compiler subsystem Example: a compiler subsystem Compiler compile () Stream StackMachineCodeGenerator CodeGenerator ByteCodeStream Symbol Parser TokenScanner ProgramNode ProgramNodeBuilder VariableNode ExpressionNode StatementNode Some specialized applications might need to access directly the classes of the compiler subsystem. Most clients don’t care about details like parsing and so on. They merely want to compile some code!!! The Compiler class acts as a façade: it offers clients a single, simple interface to the compiler subsystem.

13 Benefits of façade pattern: It hides the implementation of the subsystem from clients, making the subsystem easier to use (foreground oriented- see last slide and identify the foreground objects in this pattern) It promotes decoupling between the subsystem and its clients. This allows you to change the classes that comprise the subsystem without affecting the clients (background oriented while foreground remains intact- see last slide and distinguish these objects from one another in this pattern) It reduces compilation dependencies in large software systems It simplifies porting systems to other platforms, because it's less likely that building one subsystem requires building all others

14 Example of Behavioral Pattern - Observer Pattern  Define how several objects can be notified of a change.  Maintain dependency between objects so that when the state of one object changes, the other objects are automatically notified and updated. Subject Observer1 Observer2 Observer3  Two types of components: 1.Observer: component that might be interested in state changes (transitions or events) of the subject. The observer registers interest in specific events, and defines an updating interface through which state change notifications are made. 2. Subject: knows its observers and is expected to provide an interface for subscribing and unsubscribing observers.

15 public interface Observer { //notify an individual observer that a change has taken place public void update(); } public interface Subject { //tell the subject that an object is interested in changes public void register (Observer obs); //notify observers that a change has taken place public void notify(); }  Observers and subjects may implement the following interfaces. StockCustomer > Subject register (o:Observer) notify() > Observer update () observers notify() { for all o in observers o.update () } update() { observerState:= subject.getState() }

16 Benefits of Observer pattern: Minimal coupling between the Subject and the Observer Can reuse subjects without reusing their observers and vice versa Observers can be added without modifying the subject All subject knows is its list of observers Support for event broadcasting Subject sends notification to all subscribed observers Observers can be added/removed at any time Perhaps with this pattern it is easier to establish the relationship between the key actors in your LSCS project! See next slide…!

17 -Mediator pattern Subject1 Mediator Observer1 Subject2 Observer2 Observer3  In case where observers interact with several subjects and/or vice-versa it is more appropriate to extend the observer pattern with the mediator.  The pattern: - Defines an object that encapsulates how a set of objects interact, named Mediator. - Promotes loose coupling by keeping objects from referring to each other explicitly and lets you vary their interaction independently.

18  Example: StockCustomer > Subject register (o:Observer) notify() > Observer update () observers notify() { for all o in observers o.update () } update() { observerState:= subject.getState() } StockBroker observer > Mediator register(o:Observer) notify() update()

19 More Examples of Design Patterns  Creational patterns Factory Method pattern: provides a decision-making class that returns selectively one of several possible subclasses of an abstract base class. Abstract factory pattern: provides an interface to create and return one of several families of related objects. Builder pattern: separates the construction of a complex object from its representation so that different representations can be created according to the needs of the program.

20  Structural Patterns -Describes how classes and objects can be combined to form larger structures. Composite patterns: creates a composition of objects Proxy pattern: creates a simple object that takes the place of a more complex object which may be invoked later Façade pattern: provides a uniform interface to a complex subsystem.  Behavioral Patterns -Are concerned specifically with communication between objects. Chain of responsibility pattern: allows decoupling between objects by passing a request from one object to the other until it is recognized Command pattern: use simple objects to represent the execution of software commands Observer pattern: defines how several objects can be notified of a change.

Lab 2 Exercise 1. Open Agro UML or a UML drawing tool you are comfortable with. 2. Create a UML diagram based on the observer pattern for your LSCS system. 3. Discuss and ask questions revolving around the key actors of the LSCS system, data types, their flow from/to a relational or partitioned or central database (why you have chosen this one?) based on the observer pattern. This includes information updates/events. 4. Does the LSCS require a mediator pattern? Explain…