Software Design Lecture : 27.

Slides:



Advertisements
Similar presentations
Strategy Pattern1 Design Patterns 1.Strategy Pattern How to design for flexibility?
Advertisements

The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Design Patterns for Object Oriented systems CSC 515 Ashwin Dandwate.
Design Patterns CS is not simply about programming
Ralph Johnson - University of Illinois1 Patterns: What They Are, and How to Write Them Ralph Johnson University of Illinois at Urbana-Champaign
James Tam Introduction To Design Patterns You will learn about design techniques that have been successfully applied to different scenarios.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns.
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Design Patterns: someone has already.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Design Patterns.
Chapter 1: Introduction to Design Patterns. SimUDuck Example.
An Introduction to Software Architecture
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Advanced topics in software engineering CSC532 Term Paper Design Patterns Harpreet Singh Submitted By:-
Aniruddha Chakrabarti
Copyright © 2002, Systems and Computer Engineering, Carleton University Patterns.ppt * Object-Oriented Software Development Part 11.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
CS 325: Software Engineering February 12, 2015 Applying Responsibility-Assignment Patterns Design Patterns Situation-Specific Patterns Responsibility-Assignment.
Design Patterns Introduction to Design Patterns Eriq Muhammad Adams J. Mail : | Blog :
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
CIS 112 Exam Review. Exam Content 100 questions valued at 1 point each 100 questions valued at 1 point each 100 points total 100 points total 10 each.
CS 160: Software Engineering October 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CSC 480 Software Engineering Design With Patterns.
Design Patterns: Elements of Reusable Object- Orientated Software Gamma, Helm, Johnson, Vlissides Presented By: David Williams.
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
CS 210 Introduction to Design Patterns August 29, 2006.
Design Patterns in Context ©SoftMoore ConsultingSlide 1.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
1 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Introduction to Design Patterns.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
1 Lecture Material Design Patterns Visitor Client-Server Factory Singleton.
SE 461 Software Patterns Welcome 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
Design Patterns: Brief Examples
Strategy Pattern.
The Object-Oriented Thought Process Chapter 15
Object-Oriented Analysis and Design
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
MPCS – Advanced java Programming
Introduction to Design Patterns
A Brief Introduction to Design Patterns
Design Patterns Introduction
Design Patterns.
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
Strategy Design Pattern
Advanced Programming Behnam Hatami Fall 2017.
Introduction to Design Patterns Part 1
Patterns.
Object-Oriented Programming
Pattern-Oriented Cluster: Comp 630/650/655
Pattern-Oriented Cluster: Comp 630/650/655
Object oriented analysis and design
DESIGNING YOUR SYSTEM.
An Introduction to Software Architecture
DESIGN PATTERNS : Introduction
Pattern-Oriented Cluster: Comp 630/650/655
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
Design Patterns Lecture part 1.
Introduction to Design Patterns
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
Introduction to Design Patterns
Informatics 122 Software Design II
CSC 480 Software Engineering
Presentation transcript:

Software Design Lecture : 27

Motivation for Design Pattern Employee A works for a company which makes simulation game with name of “SimUDuck” The game show variety of ducks which can swim and quacking sounds. The initial software designer of the software apply basic design principles and come up with a class diagram as shown in next slide

The display() method is abstract, since all duck subtypes look different

Problem Due to intense pressure from the market forces the management needs an innovative features to have an competitive edge over the competitors.

Solution Management decides to hold series of brainstorming sessions to find out of the box solution Finally they come up with a feature to show the flying ducks along with other ducks

This is what the we wants!!

Employee A Thinks: It’s nothing, after all I am OO Designer, all I need to do is to add fly method in super class Duck and all the subclasses will inherit it. Its just a work of not more than a week!!! Wow that’s the greatness of OOAD

Class Diagram Proposed by Joe All subclasses inherit fly()

Problem in the Proposed Solution What Joe fail to understand is that not all the ducks fly i-e rubber duck etc but fly method is available for all the subclasses.

Root Cause A localized update in the code is having non-local side effects (rubber duck) Rubber duck also don’t quack so quack must be overridden to squeak . Improved version on next slide

Problem Joe thinks that he can just override the fly method in rubber duck class as in case of quack but fly method will do nothing !! But what if a new type of duck to be added which is not suppose to fly or quack i-e Wooden Decoy duck; as shown in next slide

Another Problem Joe just received an memo that product features will keep on changing at regular interval so he needs to keep his fingers cross all the times or rethink his decision about inheritance, because it may happen that he will be forced to override fly and quack method for every new duck subclass. He needs a cleaner solution to handle the situation in which some of the duck types may fly or quack not all!!

Innovative Solution Instead of using Inheritance Joe decides to go with Interfaces. There should be two interfaces i-e Flyable and Quackable; classes will implements as required.

Any Problem with Solution below

Maintenance Nightmare Introduction of Interfaces will destroy code reuse When ever a change is needed, you need to track down the class which implements that behavior i-e flyable; and that will introduce more bugs!! At this point you might be thinking that something magical should occur to solve the problem

Design Techniques Seperation of interface and Implementation Identify the aspects of the application which varies and separate them from what stays the same Encapsulate the varied code so it’s not effected with change.

Applying Rule to Duck Class

Magical Solution: Design Patterns Open / Close Principle and Separation of Interface and Implementation forms the basis of almost all the design patterns

What are Patterns – Inspiration from Buildings During the late 1970s, an architect named Christopher Alexander carried out the first known work in the area of patterns. Alexander and his colleagues studied different structures that were designed to solve the same problem He identified similarities that exists among quality designs

Design Patterns In 1987, influenced by the writings of Alexander, Kent Beck and Ward Cunningham applied the architectural pattern ideas for the software design and development. In 1994, the publication of the book entitled Design Patterns: Elements of Reusable Object-Oriented Software on design patterns by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides explained the usefulness of patterns and resulted in the widespread popularity for design patterns

What are Design Patterns ?? “Some body has already solve your problem” A design pattern is a documented best practice or core of a solution that has been applied successfully in multiple environments to solve a problem that recurs in a specific set of situations. It is “a recurring solution to a common problem in a given context and system of forces.”

Design Patterns – Language Independent A design pattern is an effective means to convey/communicate what has been learned about high-quality designs. The result is: – A shared language for communicating the experience gained in dealing with these recurring problems and their solutions. – A common vocabulary of system design elements for problem solving discussions. A means of reusing and building upon the acquired insight resulting in an improvement in the software quality in terms of its maintainability and reusability.

Design Patterns A design pattern is not an invention. A design pattern is rather a documented expression of the best way of solving a problem that is observed or discovered during the study or construction of numerous software systems. One of the common misconceptions about design patterns is that they are applied only in an object-oriented environment. Even though design patterns discussions typically refer to the object- oriented development, they are applicable in other areas as well.

Essence of Design Patterns Remember, knowing concepts like abstraction, inheritance, and polymorphism do not make you a good object oriented designer. A design guru thinks about how to create flexible designs that are maintainable and that can cope with change. The best way to use them is to load your mind with them and then identify places where you can apply them. Instead of code reuse, patterns let you experience reuse.

Formal Definition of Design Pattern The design pattern identifies classes and instances, their roles, collaborations and responsibilities. Each design pattern focuses on a particular object- oriented design problem or issue. It describes when it applies, whether it can be applied in the presence of other design constraints, and the consequences and trade-offs of its use.”

Design Pattern Vs FrameWorks Pattern are logical in nature. Frame works are more physical in nature, as they exist in the form of some software.

Scope Class :static. Defined through inheritance between classes Object:dynamically,defined through associations between objects Purpose Creational:design patterns for creating objects Structual:design patterns for building complex objects. Behavioral:design patterns for accomplishing complex tasks

Categories of Design Patterns

Creational Design Patterns Deal with one of the most commonly performed tasks in an OO application, the creation of objects. Support a uniform, simple, and controlled mechanism to create objects. Allow the encapsulation of the details about what classes are instantiated and how these instances are created. Encourage the use of interfaces, which reduces coupling.