CS 325: Software Engineering March 17, 2015 Applying Patterns (Part A) The Façade Pattern The Adapter Pattern Interfaces & Implementations The Strategy.

Slides:



Advertisements
Similar presentations
Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Advertisements

CS 350 – Software Design The Bridge Pattern – Chapter 10 Most powerful pattern so far. Gang of Four Definition: Decouple an abstraction from its implementation.
JDBC Session 4 Tonight: Design Patterns 1.Introduction To Design Patterns 2.The Factory Pattern 3.The Facade Pattern Thursday & Next Tuesday: Data Access.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
SWE 4743 Strategy Patterns Richard Gesick. CSE Strategy Pattern the strategy pattern (also known as the policy pattern) is a software design.
Chapter 6: Using Design Patterns
Design Patterns CS is not simply about programming
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
Façade Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Chapter 22 Object-Oriented Design
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Design Patterns Ric Holt & Sarah Nadi U Waterloo, March 2010.
Design Patterns.
Dr. Ahmad R. Hadaegh A.R. Hadaegh California State University San Marcos (CSUSM) Page 1 Virtual Functions Polymorphism Abstract base classes.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Copyright 2002 Prentice-Hall, Inc. Modern Systems Analysis and Design Third Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich Chapter 20 Object-Oriented.
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.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
Structural Pattern: Bridge When the abstract interface and the concrete implementation have been set up as parallel class hierarchies, it becomes difficult.
CSE 341, S. Tanimoto Java brief review - 1 Java Brief Review Java’s strengths Object-oriented terminology Inheritance Interfaces An example with inheritance.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
9-Dec Dec-15  INTRODUCTION.  FEATURES OF OOP.  ORGANIZATION OF DATA & FUNCTION IN OOP.  OOP’S DESIGN.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
CS 210 Final Review November 28, CS 210 Adapter Pattern.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
More Design Patterns From: Shalloway & Trott, Design Patterns Explained, 2 nd ed.
CS212: Object Oriented Analysis and Design Lecture 38: Design Pattern-II.
The Facade Pattern (Structural) ©SoftMoore ConsultingSlide 1.
CS 325: Software Engineering March 19, 2015 Applying Patterns (Part B) Code Smells The Decorator Pattern The Observer Pattern The Template Method Pattern.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
CS 5150 Software Engineering Lecture 16 Program Design 3.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
Structural Patterns C h a p t e r 4 – P a g e 55 StructuralPatterns Design patterns that describe how classes and objects can be combined to form larger.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Creational Patterns C h a p t e r 3 – P a g e 14 Creational Patterns Design patterns that deal with object creation mechanisms and class instantiation,
Examples (D. Schmidt et al)
Presented by FACADE PATTERN
Design Patterns: MORE Examples
Design Patterns: Brief Examples
Unit II-Chapter No. : 5- design Patterns
Strategy Design Pattern
Chapter 10 Design Patterns.
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Introduction to Design Patterns
Behavioral Design Patterns
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
object oriented Principles of software design
Presented by Igor Ivković
Week 6 Object-Oriented Programming (2): Polymorphism
Object Oriented Design Patterns - Structural Patterns
BRIDGE PATTERN.
CS 350 – Software Design Principles and Strategies – Chapter 14
Structural Patterns: Adapter and Bridge
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
CS 325: Software Engineering
Presented by Igor Ivković
Presentation transcript:

CS 325: Software Engineering March 17, 2015 Applying Patterns (Part A) The Façade Pattern The Adapter Pattern Interfaces & Implementations The Strategy Pattern The Bridge Pattern The Abstract Factory Pattern Designing Like An Expert

CS 325 March 17, 2015 Page 159 The Façade Pattern For instance, when certain elements of the client community need access to the functionality provided by a complex subsystem, it is undesirable to expose the client to the intricacies of interacting with this complicated subsystem. The Façade Pattern provides a unified interface to the subsystem, simplifying the client’s ability to use the subsystem. By encapsulating the complex subsystem within a single interface object, this pattern reduces the learning curve associated with using the subsystem and decouples the subsystem from its clients. Some design patterns are structural, describing how to combine objects into larger structures.

CS 325 March 17, 2015 Page 160 The Façade Pattern: An Example The Façade Pattern provides a simple interface to an entire subsystem of objects, simplifying the use of the subsystem by reducing the need for outside code to be aware of the subsystem’s inner workings, thereby improving the readability of the clients that use the subsystem. Applying the Façade Pattern to a compiler.

CS 325 March 17, 2015 Page 161 The Adapter Pattern Another structural pattern adapts the public members (or interface) of one class into those of another. When the client expects to interact with a class in a particular manner, it is sometimes necessary to “adapt” the interface of the class to accommodate those expectations. The client will call the adapter’s interface which, in turn, translates those calls into calls to the original interface of the class being adapted. This permits classes to work together in spite of incompatible interfaces.

CS 325 March 17, 2015 Page 162 The Adapter Pattern: An Example One common use of the Adapter Pattern is to adapt old legacy code to a new interface. The client uses the (x,y) position of a Rectangle’s upper left corner and the Rectangle’s width and height to draw the Rectangle. The old LegacyRectangle uses the (x,y) positions of its upper left and lower right corners to draw it. The RectangleAdapter adapts the old-style drawing to the new style by converting the client’s information about the one corner, the width, and the height into the LegacyRectangle’s information about the two corners.

CS 325 March 17, 2015 Page 163 Interfaces & Implementations To fully exploit the benefits of object-oriented design and programming, the implementation of a software module should be distinguished from its interface. Actual code of procedures and methods All private data members and member functions Allows for internal modification without affecting the way outside entities interact with the module Implementation Provides abstraction of module to outside entities Restricts access to resources to well-defined entry points, such as public members Supports polymorphism, often via inheritance from the same abstract class Interface

CS 325 March 17, 2015 Page 164 The Strategy Pattern Another type of design pattern is the behavioral pattern, which addresses common object interactions. In the Strategy Pattern, each algorithm in a family of algorithms is encapsulated and they are all made interchangeable, thus allowing the algorithm to vary independently of the clients that use it. This permits a program to switch easily between algorithms without resorting to monolithic if-else statements. This approach allows the behavior in question to be modified at run- time and not just at design time.

CS 325 March 17, 2015 Page 165 The Strategy Pattern: An Example The strategy could be the particular sorting algorithm used to organize a list. Instead of selecting the specific algorithm within the code, a run- time selection can be made, based upon the particular data set being sorted. In this way, the particular sorting algorithm chosen can accommodate the data set in question, with the sorting algorithm selected on the basis of which one provides optimal performance for the immediate data set.

CS 325 March 17, 2015 Page 166 The Bridge Pattern There are times when the interface and the implementation of a class need to vary independently. When the abstract interface and the concrete implementation have been set up as parallel class hierarchies, it becomes difficult to independently extend either the interface or the implementation. The Bridge Pattern addresses this problem by decoupling the two class hierarchies, making them orthogonal rather than parallel. In this way, the abstract interfaces can be platform-independent even when the concrete implementations are platform- dependent.

CS 325 March 17, 2015 Page 167 The Bridge Pattern: An Example Consider the notion of drawing shapes using different graphics platforms. By decoupling the Shape abstraction from the Drawing implementor, the explosion of platform-dependent shape subclasses is avoided and the amount of redundant code is minimized. With this model, individual shape alterations and additional extensions to the Shape class will only affect the abstraction portion of the model, while platform modifications will only affect the implementor portion of the model.

CS 325 March 17, 2015 Page 168 The Abstract Factory Pattern A third type of design pattern is the creational pattern, which addresses class instantiation problems. If an application needs to be portable, it needs to encapsulate platform dependencies. These platforms might include the operating system, the database management system, the windowing system, the web browser, etc. Frequently, this encapsulation isn’t engineered in advance, resulting in a massive proliferation of #ifdef case statements with options for all currently supported platforms. Rather than having clients create platform objects directly, they create abstract objects and utilize an abstract factory as an interface for producing the concrete objects.

CS 325 March 17, 2015 Page 169 The Abstract Factory Pattern: An Example Consider the development of shape-generation code that would work on two different graphics platforms. The client uses the abstract ShapeFactory to produce abstract curved and straight shapes. If the platform has been established as “simple”, concrete Circle and Square objects are created, while if the platform has been established as “robust”, concrete Ellipse and Rectangle objects are created.

CS 325 March 19, 2015 Page 170 Designing Like An Expert Christopher Alexander advocated a pattern-based approach to design that may be applied to software. Essentially, the idea is to always keep context in mind. Don’t concern yourself with instantiation problems until you’ve addressed structural issues. And don’t concern yourself with structural issues until you’ve considered how the class behaves. Begin with a conceptual understanding of the design requirements. Identify the patterns that characterize the entire design. Work inwards from the behavior of a class to its structure and ultimately to its creation. Apply the discovered patterns in order, refining the overall design in the process.

CS 325 March 17, 2015 Page 171 Designing Like An Expert: Determining Senior Patterns Adapting an interface to another interface requires that those interfaces be established first. The Bridge pattern sets up the structure of the interfaces, a prerequisite to the Adapter’s mapping of those interfaces. The Abstract Factory pattern depends on knowing which classes will be defined. The Façade pattern sets up a structure for accessing those classes. In that sense, the Façade should be established before considering the details required by the Abstract Factory. The Abstract Factory pattern depends on knowing which classes will be defined. The Façade pattern sets up a structure for accessing those classes. In that sense, the Façade should be established before considering the details required by the Abstract Factory. The Adapter pattern is concerned with the structure of both the Adapter and the Adaptee. The Strategy pattern considers how classes will interact. Those behavioral issues need to be addressed before considering the issues associated with basic structure. The Adapter pattern is concerned with the structure of both the Adapter and the Adaptee. The Strategy pattern considers how classes will interact. Those behavioral issues need to be addressed before considering the issues associated with basic structure. Adapter or Bridge? Abstract Factory or Façade? Strategy or Adapter? During the course of your design, you observe potential problems that might be addressed via two separate design patterns. Which pattern should you apply first?