cs 325: software engineering february 12, 2015 applying responsibility-assignment patterns design...
TRANSCRIPT
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
Design Patterns
CS 325February 12, 2015Page 2
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.
Design Patterns
CS 325February 12, 2015Page 3
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.
Situation-Specific Patterns
CS 325February 12, 2015Page 4
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.
Responsibility-Assignment Patterns
CS 325February 12, 2015Page 5
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.
The Controller Pattern
CS 325February 12, 2015Page 6
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.
The Expert Pattern
CS 325February 12, 2015Page 7
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?
The Creator Pattern
CS 325February 12, 2015Page 8
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