Software Design Lecture : 35.

Slides:



Advertisements
Similar presentations
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
Advertisements

JDBC Session 4 Tonight: Design Patterns 1.Introduction To Design Patterns 2.The Factory Pattern 3.The Facade Pattern Thursday & Next Tuesday: Data Access.
Solutions to Review Questions. 4.1 Define object, class and instance. The UML Glossary gives these definitions: Object: an instance of a class. Class:
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Composite Design Pattern (1) –A structural design pattern.
Modified from Sommerville’s originalsSoftware Engineering, 7th edition. Chapter 8 Slide 1 System models.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
The Unified Modeling Language (UML) Class Diagrams.
Pattern Abstract Factory
Seven Habits of Effective Pattern Writers Facade Pattern PH pp GoF pp John Klacsmann.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Façade Design Pattern (1) –A structural design pattern.
Composite Design Pattern. Motivation – Dynamic Structure.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Composit Pattern.
SOFTWARE DESIGN AND ARCHITECTURE
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 10 Use Case Design.
Lab 04.
The Adapter Pattern SE-2811 Dr. Mark L. Hornick 1.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 14 Slide 1 Object-oriented Design.
The Static Analysis Model Class Diagrams Prof. Hany H. Ammar, CSEE, WVU, and Dept. of Computer Science, Faculty of Computers and Information, Cairo University.
Facade Introduction. Intent Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the.
The Façade Pattern SE-2811 Dr. Mark L. Hornick 1.
Structural Design Patterns
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
Chapter 9 Putting together a complete system. This chapter discusses n Designing a complete system. n Overview of the design and implementation process.
FacadeDesign Pattern Provide a unified interface to a set of interfaces in a subsystem. Defines a high level interface that makes the subsystem easier.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
JAVA DESIGN PATTERN Structural Patterns - Facade Pattern Presented by: Amit kumar narela Ise Ise
Adapter and Façade Patterns By Wode Ni and Leonard Bacon-Shone.
The Facade Pattern (Structural) ©SoftMoore ConsultingSlide 1.
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.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
Software Modelling Class Diagram. Class Diagrams The main building block in object oriented modeling They are used both for general conceptual modeling.
Engineering, 7th edition. Chapter 8 Slide 1 System models.
BTS530: Major Project Planning and Design
Object-Orientated Analysis, Design and Programming
Object-Orientated Analysis, Design and Programming
UML Diagrams: Class Diagrams The Static Analysis Model
Object-Orientated Design: Part 2
Façade Pattern:.
Object-Oriented Analysis and Design
MPCS – Advanced java Programming
Conception OBJET GRASP Patterns
Observer Design Pattern
Abstract descriptions of systems whose requirements are being analysed
Composite Pattern SE2811 Software Component Design
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Decorator Design Pattern
Intent (Thanks to Jim Fawcett for the slides)
Chapter 8, Object Design Introduction to Design Patterns
Object Oriented Analysis and Design
Jim Fawcett CSE776 – Design Patterns Summer 2003
Lecture 22 Inheritance Richard Gesick.
Systems Analysis and Design With UML 2
Object Oriented Design Patterns - Structural Patterns
Object-Oriented Design
Software Design Lecture : 9.
An Introduction to Software Architecture
Design pattern Lecture 9.
13. Composite Pattern SE2811 Software Component Design
10. Façade Pattern SE2811 Software Component Design
13. Composite Pattern SE2811 Software Component Design
Design Yaodong Bi.
Software Design Lecture : 39.
Software Design Lecture : 38.
Software Design Lecture : 28.
Software Design Lecture : 36.
Presentation transcript:

Software Design Lecture : 35

Façade Design Pattern

Scenario – Building a Movie Theatre You have decided to build your own home theatre compromising of the some what following components: DVD Player Sound Systems Amplifiers Projector Screen CD Player Theatre Lights etc You have spend a lot of time making all the connections to make it work

Classes in Building Home Theatre

Steps in Watching the Movie Dim the lights Turn the projector on Connect DVD to Projector Turn on the sound Amplifier on Connect Amplifier input to DVD Adjust the sound Set the DVD Player on Watch the movie Exhausted !!! Is it that difficult to watch a movie Think about turning off the Home Theatre

Need for Simplicity At this point in time Façade is what you need Façade let you use the complex system by providing a simple interface to use the complex sub systems Power of subsystems is still there but the complexity is reduced by availability of simpler interface to interact with

Simplified Class Diagram

Façade Design Pattern Defined Façade provides a unified interface to a set of interfaces in a subsystem. It define a higher level interface which is easier to use

Façade Design Pattern continue… Façade decouple the client from interacting with the subsystems instead Façade take up the responsibility of dealing with the subsystems itself. Façade will not add any extra functionality it will just simply the access to functionality. Client can also access subsystems directly as if there is no Façade.

Client Access without Facade

Client Access with Facade

Class Diagram of Facade

New Software Design Principle The Principle of Least Knowledge “Talk only to your immediate friends” When creating software design for any object be careful of the number of classes it is interacting with and how it will be interacting with them

Guidelines for Implementing Principle Suppose we have an object with several methods, now for that object we should invoke methods only that belongs to: An Object itself Object passed in as a parameter Any method that object creates or instantiates. Any component of the Object

Rules Explained with Example

Applying Principle in Facade There can be several Façade within One Façade with the increase in complexity. We aim to maintain minimum possible communication with other classes.

Example For an typical online transaction oriented system, customer can perform transactions against an account i- e Pay pal etc; credit card validators are used for verifying the creditionals of a client submitted by the client for checkout purposes. Address of the customer is also stored and checked for data entry checks for shipment purposes. Usually account, address and credit card subsystems works together to provide the feature of online transaction.

To Do Tasks: Build an application which perform the following tasks Accepts customer details (account, address and credit card details) Validates the input data Saves the input data to appropriate data files Assuming there are three classes and each class is having its own validation and data storage mechanism

Sequence Diagram of System

Sequence Diagram with Facade

Advantages of Facade It shields the client from subsystem components, thereby reducing the number of objects that clients have to deal with. It promote weak coupling between the subsystems and its client. Clients can directly access subsystems also, it provide choice between ease use and generality

Software Design Lecture : 36

Composite Design Pattern

Motivation for Composite Design Pattern Every component or object can be classified into one of the two categories — Individual Components Composite Components — which are composed of individual components or other composite components

Intend of Composite Design Pattern To have a common interface for both individual and composite components so that client programs can view both the individual components and groups of components uniformly. Usually a Tree structure having nodes and leave nodes represents composite and individual components respectively.

Discussion on Whole-Part relation

Aggregation or “ has –a “ relationship Specialized form of association i-e Weak Association. Assembling a class from other classes. Aggregation is a special type of relationship used to model a "whole to its parts" relationship Part class is independent from the whole class's lifecycle.

Aggregation In an aggregation relationship, the child class instance can outlive its parent class. Child class can be a part of multiple parent classes. To represent an aggregation relationship, you draw a solid line from the parent class to the part class, and draw an unfilled diamond shape on the parent class's association end

Example

Aggregation Example

Tree Structure Revisited

Composite Pattern Defined Composite Design pattern allow us to compose objects into tree structures to represent whole- part hierarchy . It let the client handle the composite and individual components in a uniform manner

Class Diagram of Composite Design Pattern

Example of Composite Pattern Let us create an application to simulate the Windows/UNIX file system. The file system consists mainly of two types of components — directories and files. Directories can be made up of other directories or files, whereas files cannot contain any other file system component. In this aspect, directories act as nonterminal nodes and files act as terminal nodes or leaf node of a tree structure.

Design Approach Let us define a common interface for both directories and files in the form of a Java interface FileSystemComponent The FileSystemComponent interface declares methods that are common for both file components and directory components. Let us further define two classes — FileComponent and DirComponent — as implementers of the common FileSystemComponent interface as shown in next slide

Class Diagram of Proposed Approach

Description of Classes FileComponent The FileComponent class represents a file in the file system and offers implementation for the following methods. getComponentSize() This method returns the size (in kilobytes) of the file represented by the File- Component object.

Class Descriptions DirComponent This class represents a directory in the file system. Since directories are composite entities, the DirComponent provides methods to deal with the components it contains. These methods are in addition to the common getComponentSize method declared in the FileSystemComponent interface.

Class Description addComponent(FileSystemComponent) This method is used by client applications to add different DirComponent and FileComponent objects to a DirComponent object. getComponent(int) The DirComponent stores the other FileSystemComponent objects inside a vector. This method is used to retrieve one such object stored at the specified location.

Class Description getComponentSize() This method returns the size (in kilobytes) of the directory represented by the DirComponent object. As part of the implementation, the DirComponent object iterates over the collection of FileSystemComponent objects it contains, in a recursive manner, and sums up the sizes of all individual FileComponents. The final sum is returned as the size of the directory it represents.

Processing of Class Diagram A typical client would first create a set of FileSystemComponent objects (both DirComponent and FileComponent instances). It can use the addComponent method of the DirComponent to add different FileSystemComponents to a DirComponent, creating a hierarchy of file system (FileSystemComponent) objects.

Calculating the Size of Object When the client wants to query any of these objects for its size, it can simply invoke the getComponentSize method. The client does not have to be aware of the calculations involved or the manner in which the calculations are carried out in determining the component size. In this aspect, the client treats both the FileComponent and the DirComponent object in the same manner. No separate code is required to query FileComponent objects and DirComponent objects for their size.

Problem in Current Design Client to keep track when calling a non-common method like addcomponent and getcomponent as these methods exists only in DirComponent

Design Approach -II Provide the same advantage of allowing the client application to treat both the composite DirComponent and the individual FileComponent objects in a uniform manner while invoking the getComponentSize method

public abstract class FileSystemComponent { String name; public FileSystemComponent(String cName) { name = cName; } public void addComponent(FileSystemComponent component) throws CompositeException { throw new CompositeException( "Invalid Operation. Not Supported"); public FileSystemComponent getComponent(int componentNum) public abstract long getComponentSize(); }//End of class FileSystemComponent

Code in Word File