Download presentation
Presentation is loading. Please wait.
Published byRoland Carroll Modified over 9 years ago
2
CS 325: Software Engineering February 12, 2015 Applying Responsibility-Assignment Patterns Design Patterns Situation-Specific Patterns Responsibility-Assignment Patterns The Controller Pattern The Expert Pattern The Creator Pattern
3
Design Patterns CS 325 February 12, 2015 Page 87 Design patterns are general repeatable solutions to commonly occurring problems in software design. Patterns originated as an architectural concept by Christopher Alexander in the late 1970s.
4
Design Patterns CS 325 February 12, 2015 Page 88 In 1987, Kent Beck and Ward Cunningham began experimenting with the idea of applying patterns to programming. Design patterns gained popularity in computer science after the 1994 publication of Design Patterns: Elements of Reusable Object-Oriented Software by the “Gang of Four”: Erich Gamma, Richard Helm, Ralph Johnson, & John Vlissides.
5
Situation-Specific Patterns CS 325 February 12, 2015 Page 89 The classical Gang-of-Four design patterns are situation- specific, where each pattern is applied to particular type of software design problem. Stuctural Patterns describe how to combine objects into larger structures. Creational Patterns employ methods and objects to instantiate other objects. Behavioral Patterns address common object interactions.
6
Responsibility-Assignment Patterns CS 325 February 12, 2015 Page 90 A second type of design pattern, developed by Craig Larman in 2005, focuses on assigning appropriate responsibilities to the objects within a software system. High Cohesion ensures that the responsibilities of a given software element are strongly related and highly focused (e.g., breaking programs into classes and subsystems). Loose Coupling assigns responsibilities to support lower dependency between the classes and higher reuse potential by ensuring that change in one class has little impact on other classes. Polymorphism assigns the responsibility of defining any variation of behavior based upon type to the types for which the variation happens.
7
The Controller Pattern CS 325 February 12, 2015 Page 91 Having the user interface of a system handle user requests to the system forces the UI to know too much about the internal system, but having the internal system handle user requests forces the internal system to know too much about the UI. Inserting a “controller” class in between the UI and the internal system loosens their coupling, reducing the change effect that they have on each other.
8
The Expert Pattern CS 325 February 12, 2015 Page 92 The Expert Pattern assigns the responsibility for handling a functional request to an object that has the information (e.g., the attributes) to fulfill the request. In this partial card game model, which class should handle requests for the current scoreboard?
9
The Creator Pattern CS 325 February 12, 2015 Page 93 The Creator Pattern addresses the issue of assigning responsibility for object creation. Consider giving Class A responsibility for creating objects of Class B if: Class A is an aggregation of Class B (i.e., A consists of B objects) Objects of Class A contain objects of Class B Objects of Class A maintain objects of Class B Objects of Class A frequently use objects of Class B Objects of Class A have the information to create objects of Class B
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.