Keywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator.

Similar documents
SDC Design patterns GoF

Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.)

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

The Strategy Pattern Design Principle: Design Principle: Design Principle:

Design Patterns. An introduction

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Design patterns. Jef De Smedt Beta VZW

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

Object-Oriented Oriented Programming

Using Design Patterns in Java Application Development

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

Object-oriented Software Design Patterns

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Socket attaches to a Ratchet. 2) Bridge Decouple an abstraction from its implementation so that the two can vary independently.

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout

Design Patterns: Structural and Behavioural

INSTITUTE OF AERONAUTICAL ENGINEERING

Slide 1. Design Patterns. Prof. Mirco Tribastone, Ph.D

DESIGN PATTERN - INTERVIEW QUESTIONS

Review Software Engineering October, 7, Adrian Iftene

Introduction to Software Engineering: Object Design I Reuse & Patterns

Laboratorio di Progettazione di Sistemi Software Design Pattern Creazionali. Valentina Presutti (A-L) Riccardo Solmi (M-Z)

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Object-Oriented Design

UNIT I Introduction to Design Patterns

Software Design COSC 4353/6353 D R. R A J S I N G H

A Reconnaissance on Design Patterns

Design Pattern and Software Architecture: IV. Design Pattern

Object Oriented Paradigm

LECTURE NOTES ON DESIGN PATTERNS MCA III YEAR, V SEMESTER (JNTUA-R09)

Brief Note on Design Pattern

An Introduction to Patterns

Object-Oriented Design

Design Patterns Reid Holmes

Design Patterns V Structural Design Patterns, 2

UNIT I Introduction to Design Patterns

Design Patterns. Observations. Electrical Engineering Patterns. Mechanical Engineering Patterns

Composite Pattern. IV.4 Structural Pattern

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

OODP Session 4. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

DESIGN PATTERNS SURESH BABU M ASST PROFESSOR VJIT

Design Patterns. Dr. Rania Khairy. Software Engineering and Development Tool

Design Patterns. Gunnar Gotshalks A4-1

Applying the Observer Design Pattern

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Creational Design Patterns

SYLLABUS CHAPTER - 1 [SOFTWARE REUSE SUCCESS FACTORS] Reuse Driven Software Engineering is a Business

Design Patterns. GoF design patterns catalog

Design Patterns. SE3A04 Tutorial. Jason Jaskolka

Creational Patterns. Factory Method (FM) Abstract Factory (AF) Singleton (SI) Prototype (PR) Builder (BU)

Lecture 20: Design Patterns II

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Object Oriented Methods with UML. Introduction to Design Patterns- Lecture 8

The Design Patterns Matrix From Analysis to Implementation

Design Patterns. CSE870: Advanced Software Engineering (Design Patterns): Cheng

CS342: Software Design. November 21, 2017

Tuesday, October 4. Announcements

3 Product Management Anti-Patterns by Thomas Schranz

Design Patterns. Hausi A. Müller University of Victoria. Software Architecture Course Spring 2000

Overview CS Kinds of Patterns. Design Pattern. Factory Pattern Rationale. Kinds of Factory Patterns

Applying Design Patterns to SCA Implementations

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

design patterns FOR B.tech (jntu - hyderabad & kakinada) (IV/I - CSE AND IV/II - IT) CONTENTS 1.1 INTRODUCTION TO DESIGN PATTERNS TTERNS... TTERN?...

Design Pattern- Creational pattern 2015

CSCI Object Oriented Design: Frameworks and Design Patterns George Blankenship. Frameworks and Design George Blankenship 1

Design Patterns! Acknowledgements!

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

Design of Software Systems (Ontwerp van SoftwareSystemen) Design Patterns Reference. Roel Wuyts

The GoF Design Patterns Reference

Topics in Object-Oriented Design Patterns

Software Eningeering. Lecture 9 Design Patterns 2

administrivia today UML start design patterns Tuesday, September 28, 2010

Design Patterns Lecture 2

Applying the Decorator Design Pattern

Design Patterns #3. Reid Holmes. Material and some slide content from: - GoF Design Patterns Book - Head First Design Patterns

APPLYING DESIGN PATTERNS TO SCA IMPLEMENTATIONS

Applying the Factory Method Design Pattern

Design patterns generic models

1 Software Architecture

Goals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming

INTERNAL ASSESSMENT TEST III Answer Schema

CSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Iterator Pattern George Blankenship

CSE870: Advanced Software Engineering (Cheng) 1

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

Information systems modelling UML and service description languages

Think of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern

CSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Template Method Pattern. George Blankenship

Summary of the course lectures

A few important patterns and their connections

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade

Application Architectures, Design Patterns

Design Patterns Revisited

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns

Chapter 1. OO e OO. (Pattern) Alexander) (context) (elements) k. (issue) Š. (name) (classification)

GoF Design Pattern Categories

Design Patterns. (and anti-patterns)

Transcription:

Comparative Study In Utilization Of Creational And Structural Design Patterns In Solving Design Problems K.Wseem Abrar M.Tech., Student, Dept. of CSE, Amina Institute of Technology, Shamirpet, Hyderabad Email: waseem0210@gmail.com and Prof. R.M.Noorullah Professor, Department of CSE, Amina Institute of Technology, Shamirpet, Hyderabad Email :noorullahrm@gmail.com ABSTRACT:- Design Patterns solve specific design problems and make an object oriented design more flexible and reusable. They help designers reuse several designs, to choose design alternatives and to avoid alternatives that compromise reusability. To solve various design problems Creational, Structural and Behavioral patterns are used. In the present paper comparative study in utilization of Creational and Structural Design Patterns proposed to solve design problems by considering how they all encapsulate knowledge and hide instances of these classes. A critical study made for utilization of these patterns in solving design problems with some case studies and also relationship among these patterns presented with the help of design tools. Keywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator. 1. INTRODUCTION Design Patterns are descriptions of communicating objects and classes that are customized to solve a design problem at a particular context. It identifies the participating classes and interfaces, their roles, collaboration and distribution of responsibilities. Design Patterns solve specific design problems and make an object oriented design more flexible and reusable. They help designers reuse several designs, to choose design alternatives and to avoid alternatives that compromise reusability. To solve various design problems Creational, Structural and Behavioral patterns are used. Each Design pattern focuses on a particular OO Design problem or issue. Design patterns will be discussed by its name, classification, intent, structure, participants and by its implementations. They vary in their granularity and level of abstraction. Creational, Structural and Behavioral Patterns are various types of design patterns based on their purpose. In Section 2 Object Oriented Design Heuristics, in section3 Description and Selection of a Design Pattern to solve a design problem, in section 4 Description of common causes of design problem and proposed solution by using Creational and Structural design patterns, in section 5 step by step approach to use a right design pattern to solve design problem, in section 6 Study of Utilization of Creational and Structural Design patterns in solving design problems with real systems implementation, in section 7 relationships among Creational and Structural Design Patterns and Conclusion in section 8. 2.OBJECT ORIENTED DESIGN HEURISTICS OOD Heuristics are used for design improvement. They are language independent and allow us to rate the integrity of a software design. The heuristics cover important topics ranging from classes and objects to physical OOD. Synergy will exists between design heuristics and design patterns. Heuristics can highlight a problem, while patterns can provide the solution. These heuristics will deal with classes and objects used, OO applications, relationships between classes and objects, class specific data, behavior and physical OOD. Rigidity, Fragility, Immobility and Viscosity are signs of poor design architecture. For Validating quality of OOD Class / Method construct by WMC, Class/Message construct by RFC, Class/Cohesion construct by LCOM, Coupling construct by CBO, inheritance construct by DIT and NOC metrics are used. Some important heuristics are Minimize the number of messages in protocol of a class Classes should only exhibit nil or export coupling with other classes. Keep related data and behavior at one place. Do not create god classes or god objects, because they exhibit non communicating behavior. Eliminate irrelevant classes and classes that are outside the system. Minimize fan out in a class. International Academic and Industrial Research Solutions (IAIRS) Page 18

All data in a base class should be private; do not use protected data. All abstract classes must be base classes and vice versa. Construct reusable frameworks rather than reusable components. 3.DESCRIPTION AND SELECTION OF DESIGN PATTERN Design Patterns are described in graphical notation with UML diagrams which capture the end product of design processes. To reuse the design record the designs, alternatives by describing them with pattern name and classification, intent, motivation, applicability, structures, participants, collaboration, implementation and their uses in real systems. Design Patterns vary in their granularity and level of abstraction. Creational design Patterns concern the process of object creation, Structural patterns deal with composition of classes or objects and Behavioral patterns deals the way in which classes or objects intent and distribute responsibilities. There are several different approaches to find design patterns that are right to solve one design problem. Some of them by considering how design patterns solve design problems, by studying relationship among patterns, by studying patterns of like purpose, by examining cause of redesign and by considering what should be variable in our design. Creational Design Patterns Structural Design Patterns Behavioral Design Patterns Class Object Class Object Class Object Factory Method Adapter Template Method Interpreter Abstract Factory Builder Prototype Singleton Bridge Composite Decorator Façade Flyweight Proxy Chainof Responsibility Command Iterator Mediator Memento Observer State Strategy Visitor 4. COMMON CAUSES AND PROPOSED SOLUTION FOR DESIGN PROBLEMS BY USING CREATIONAL AND STRUCTURAL DESIGN PATTERNS Design patterns solve many problems faced by Object Oriented designers in many different ways. Some common causes of design problems and proposed solutions by using creational, structural and behavioral patterns are tabulated Design Problem Proposed Solution Design Pattern(s) Used Creating an object by specifying a Create Objects indirectly Abstract Factory, Factory Method, class explicitly Prototype Dependence on h/w and s/w Design to limit platform Abstract Factory platform dependencies Dependence on object Change object when needed Abstract Factory implementation Algorithmic Dependencies Algorithms likely to be changed Builder should be isolated Tight Coupling Design with loose coupling Abstract Factory Inability to alter classes Modify a class that cannot be Adapter conveniently modified Class with only one instance Provide global point to access Singleton Represent Physical Structure Represent Part-Whole hierarchies Composite Construct Physical Structure Define family of algorithms Strategy Establishing User Interface Provide sub classing for extending Decorator functionality Support multiple look and feel Portability across h/w and s/w Abstract Factory Support user operations Encapsulate request as an object Command Support multiple windows Decouple an abstraction from its implementation Define new operation without Represent operation of an object changing class structure Convert from one format to many Separate the construction of complex object from its Bridge, Abstract Factory Visitor Builder International Academic and Industrial Research Solutions (IAIRS) Page 19

representation Construct a Framework of an Define an interface for creating an Factory Method application object Customize a Framework of an Create using prototype instance and Prototype application create new object by copying Designed for reuse, but not reusable Convert the interface of a class into Adapter another interface Client code platform dependent Decouple an abstraction from its Bridge implementation Build Complex system from its Compose objects into tree structures Composite simple component To add responsibility to an Sub classing for extending Decorator individual object not to an entire functionality class Minimize communication and Provide a unified interface Façade dependencies between subsystems Application does not depend on Use sharing to support large no of Flyweight object identity fine grained objects Create expensive object on demand Provide a surrogate Proxy To avoid coupling Give multiple objects a chance to Chain of Responsibility handle a request To support undo Encapsulate a request as an object Command To represent grammar rule for Use abstract class regular expression Interpreter classes Providing uniform interface for Create aggregate object Iterator traversing To customize specific dependencies Define an object that encapsulate set Mediator of objects To record internal state of an object Store a snap shot Memento Maintain consistency between One-to-many dependencies Observer related objects Design an object that exhibit Use an abstract class State different behavior in each state Different algorithms at different Define classes that encapsulate Strategy times Design an algorithm without Design Concrete classes relies on Template Method changing its structure abstract class Represent an operation without Packaging related operations Visitor changing the class Visit across class hierarchies Traverse by calling their operations Visitor To resolve incompatible interfaces Convert original interface of a Adapter, Strategy component into another interface For better cohesion Create a pure fabrication object Abstract Factory To design with exactly one instance Define a static method of a class that Singleton of a class return a single term. To design for varying, but related algorithm or policies Define each algorithm/policy in a separate class with a common interface. Define class for composite Strategy To treat a composition structure of Composite an object as a non composite object To design a common, unified Define single point of construct to Façade interface to a set of implementation the subsystem To design publisher which wants to Define a subscriber or listener Observer maintain low coupling to subscriber interface Recovery from remote service Location transperancy using service Adapter failure look up Failure to a local service from Add a level of indirection with a Proxy product information surrogate proxy object To create families of related classes Define concrete factory class for Abstract Factory International Academic and Industrial Research Solutions (IAIRS) Page 20

that implement a common interface each family of thing to create. To create persistence objects Persistence service from a Template Method persistence framework To access a persistence service Provide a unified interface to a Façade subsystem To design a transaction Make each task a class that Command implements a common interface Creational design patterns help to make a system independent of how its objects are created, composed and represented. A class creational patterns use inheritance to vary the class that is instantiated, an object creational pattern will delegate instantiation to another object. They encapsulate knowledge about which concrete classes the system uses and how they hide instances which are created. If creational patterns are competitors then either Prototype or Abstract Factory could be used. If they are complementary then Builder can use one of other patterns to implement. 5.STEP BY STEP APPROACH TO USE A RIGHT DESIGN PATTERN TO SOLVE DESIGN PROBLEM Once we have picked a design pattern to solve a design problem apply the following step-by-step procedure effectively: Step1: Pay particular attention to the applicability and consequences of selected design pattern(s) to solve design problem. 2: Understand the classes and objects in the pattern and relationship among them by knowing their participants, structure and collaboration. 3: Implement the pattern with specific code. 4: Name Pattern Participants used in solving design problem. 5: Identify existing classes that pattern will affect and modify them accordingly. 6: Use responsibilities and collaborations associated with each operation involved. 7: Implement the operations to carry out the responsibilities and collaborations in the selected pattern(s) to solve the design problem 6. STUDY OF UTILIZATION OF CREATIONAL AND STRUCTURAL DESIGN PATTERNS IN SOLVING DESIGN PROBLEMS Factory method or Visual constructor lets a class defer instantiation to subclasses and define an interface for creating an object and to construct a frame work for an application. While implementing two aspects to be considered are when creator class is an abstract class and when is a concrete class. Templates can used to avoid sub classing. Abstract Factory or Kit provide an interface for creating families of related objects without specifying concrete classes, to create objects indirectly to implement loose coupling, to create pure fabrication object. When an application needs only one instance it can be implemented as Singleton. Builder, separate the constructions of a complex object from its representation and to convert from one format to another. An abstract builder class defines an operation for each component, which overrides operations for components. Prototype, specify the kinds of objects to create using prototypical instance and to create a new object by copying this prototype. It will be implemented by using a prototype message or by clone operation. Singleton, ensure a class only has one instance, and to provide global point of access. Design starts by using Factory Method and evolve towards other creational patterns. Designs that use Abstract Factory, Prototype and Builder are more flexible than those of Factory Method. To build primitive and Composite objects Composite is used. For sharing objects Flyweight pattern is used. To represent a set of objects in a subsystem a Façade is used. To separate objects abstraction from its implementation Bridge pattern is used. To add responsibilities to an object dynamically Decorator is used. To represent part-whole hierarchies Composite is used. To provide surrogate Proxy is used. To convert interface of a class into another interface client expect International Academic and Industrial Research Solutions (IAIRS) Page 21

Adapter is used. Adapter and Bridge promote flexibility. Composite and Decorator have a similar structure design. Decorator and Proxy provide a level of indirection to an object. 1.Consider a user interface that support multiple look and feel standards for Fund Transfer design problem. Different look and feel define different appearances and behaviors for this user interface Fund Transfer like through ATM counters, Bank counters and Net banking. Design to be portable across look and feel standards we solve this problem by defining and Abstract Fund Transfer Factory design pattern that declares an interface for creating each basic kind, which represented with design tool in fig.1a and another case for Interviewing technique for a particular candidate, represented in fig.1b and a user interface tool kit that support portability, is solved by defining an abstract factory design pattern represented in fig 1c. 2.Consider a Parse Text document to convert into different formats that can be edited interactively. Problem is the number of possible conversions should be easy to add a new conversion without modifying the reader. Solution to this problem is by defining Builder design pattern to configure PTF Reader with a text command object, which is represented in fig.2a and another case of Traversal technique of a Binary Tree represented in fig. 2b. 3.Consider a framework for application that can present multiple transactions ( local and global ) to the user. Two abstractions in this framework are the Class Application and Transaction. The Factory Method design pattern offers a solution to this design problem. It encapsulates the knowledge of which transaction subclasses to create and moves this knowledge out of the framework, which is represented with the help of tool design in fig.3. 4.Consider to build an editor for music scores by customerizing a general framework for Graphical editors and adding new objects notes, rests and staves. The solution for this design problem lies in making graphic tool create a new graphic by copying an instance called Prototype design pattern represented in fig.4a by using design tool 5. Consider some classes to have exactly on instances for example Many printers in a system, only one Printer Spooler and another case one file system with one window manager. Such types of design problems will be solved with the help of Singleton design pattern which is represented in fig. 5a and 5b. 7.RELATIONSHIPS AMONG CREATIONAL DESIGN PATTERNS After selecting design pattern(s) to solve design problem we have to understand classes and objects participates by studying the structure, participants, responsibilities and collaborations of each pattern and relationships existing among them. Relationship among Creational design patterns represented in the fig 6. In fig 7 relationship among structural components of Creational design patterns and in fig.8 relationship among creational design patterns for Presentation Manager are shown. International Academic and Industrial Research Solutions (IAIRS) Page 22

International Academic and Industrial Research Solutions (IAIRS) Page 23

International Academic and Industrial Research Solutions (IAIRS) Page 24

. International Academic and Industrial Research Solutions (IAIRS) Page 25

Builder creating components Prototype Factory Method Singleton configure impement by has one instance Abstact Factory Relationship among Creational Design Patterns fig 6 International Academic and Industrial Research Solutions (IAIRS) Page 26

International Academic and Industrial Research Solutions (IAIRS) Page 27

8. CONCLUSION The purpose of this paper is to study utilization of Creational and Structural Design Patterns in solving design problems of Object Oriented Design. Some of them are identified and proposed solution suggested with relevant design patterns. Some case studies in designing real systems are considered with some design problems and solutions proposed by using Creational design patterns are represented with UML diagrams by using Rational Rose software. Relationships among Creational and Structural design patterns, relationships among structural components of Creational design patterns presented. REFERENCES [1] European Conference on Object Oriented Programming, pages 21-35, Kaiserlautern, Germany, July1993. [2] European Conference on Object Oriented Programming, pages 139-149, Bologna, Italy, July1994 [3] Object Oriented Analysis and Design with Applications, Benjamin/Cummings, 1994, Second Edition. [4] ACM Transactions on Programming Languages and Systems, pages 343-387, October 1981. [5] An Object Oriented System in C++ Communications of the ACM, pages 117-126, September 1993. [6] ACM User Interface Software Technologies Conference, pages 92-101, Snowbird, UT, October 1990. [7] Software Reusability, Volume II: Applications and Experience, pages 269-287, Reading MA, 1989. [8] Object Oriented Programming Systems, Languages and Applications Conferences Proceedings, pages 214-223, Portland, November 1986. [9] Proceedings of the USENIXC++ Conference, pages 51-63, Washington, April 1991. [10] Object Oriented Design Heuristics by Reil. [11] Object Models by Coad. [12] Designing Object Oriented Software by Brock. [13]The Unified Modeling Language Reference Manual 2e, Addison-Wesley, Rumbaugh J, Jacobson and Booch International Academic and Industrial Research Solutions (IAIRS) Page 28