Software design - Lecture 27. The main topics covered in this chapter include: motivation for design pattern; class diagram proposed by Joe; problem in the proposed solution; maintenance nightmare; design techniques; applying rule to duck class;...
1 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 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 Problem in the Proposed Solution What Joe fail to understand is that not all the ducks fly ie rubber duck etc but fly method is available for all the subclasses 10 Root Cause A localized update in the code is having nonlocal side effects (rubber duck) Rubber duck also don’t quack so quack must be overridden to squeak . Improved version on next slide 18 19 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 20 Applying Rule to Duck Class 21 Magical Solution: Design Patterns Open / Close Principle and Separation of Interface and Implementation forms the basis of almost all the design patterns 22 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 23 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 ObjectOriented 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 24 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.” 25 Design Patterns – Language Independent A design pattern is an effective means to convey/communicate what has been learned about highquality 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 26 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 objectoriented environment. Even though design patterns discussions typically refer to the object oriented development, they are applicable in other areas as well 27 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 28 Formal Definition of Design Pattern The design pattern identifies classes and instances, their roles, collaborations and responsibilities. Each design pattern focuses on a particular objectoriented 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 tradeoffs of its use.” 29 Design Pattern Vs FrameWorks 30 31 Categories of Design Patterns 32 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 ... 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... architectural pattern ideas for the? ?software? ?design and development In 1994, the publication of the book entitled Design Patterns: Elements of Reusable ObjectOriented? ?Software? ?on design patterns ... of reusing and building upon the acquired insight resulting in an improvement in the? ?software? ?quality in terms of its maintainability and reusability 26 Design Patterns A design pattern is not an invention. A design pattern is rather a