Title: cs2340: ResponsibilityDriven Design
1cs2340 Responsibility-Driven Design
Several slides are adapted from Rebecca
Wirfs-Brock and Associates
2Homework 3
- Use Swiki to navigate to Spring 2003 Milestones
page. http//coweb.cc.gatech.edu/cs2340/2714 - Form a team of 3-4 students (Does not have to be
final project team) - Due October 2 in class
- Prepare the following artifacts to design the
Squeaken system (M3 M5)
3HW3 Artifacts
- List of your brainstormed classes (5)
- CRC Cards for your filtered classes (20)
- Good scenarios that cover uses of the application
(20) - Roles and Stereotypes identified (10)
- Architecture (Conceptual, others if needed)(10)
- Application and Utility classes UML Class Diagram
(20) - Identify Trust Boundaries (5)
- Each person write one contract for an object (5)
- Give a general exception handling strategy (5)
4From Analysis to Design
- Refine Domain Objects with Roles and
Responsibilities - Create Architecture
- Add Application Objects
- Add Utility Objects
- Refine Collaborations
- Refine Object Contracts
- Design Exception Handling Mechanisms
5Class Exercise Part I
6(No Transcript)
7Goal of RDD
To move from thinking about objects as data
algorithms to thinking about objects as roles
responsibilities
8Lets Design a Horse!!
Data-Driven Procedural Event-Driven Responsibility
-Driven
9Responsibility-Driven Design Principles
- Maximize Abstraction
- Initially hide the distinction between data and
behavior. - Think of objects responsibilities for knowing,
doing,and deciding - Distribute Behavior
- Promote a delegated control architecture
- Make objects smart have them behave
intelligently, not just hold bundles of data - Preserve Flexibility
- Design objects so interior details can be readily
changed
10RDD Constructs
- an application a set of interacting objects
- an object an implementation of one or more
roles - a role a set of related responsibilities
- a responsibility an obligation to perform a
task or know information - a collaboration an interaction of objects or
roles (or both) - a contract an agreement outlining the terms of
a collaboration
11Two Ways to Think About Roles
- Primary - Responsibilities that make an object
unique - Secondary Responsibilities that allow an object
to fit into the community of cooperating objects.
12Role Stereotypes
- Controller (direct activities)
- Coordinator (delegates work)
- Structurers (maintain relationships)
- Information Holder (keep facts)
- Service Provider (perform operation)
- Interfacer (support internal/external
communication)
13Stereotype Examples
- ATM Machine SessionController (Controller)
- Word Processor FontManager (Coordinator)
- File System Folder (Structurer)
- Pay System Employee (Information Holder)
- Pay System PayReport (Service Provider)
- ATM Machine CashDispenser (Interfacer)
14More on Roles
- Represent how we view the object from outside
looking in - Dynamic during early design
- Use to what-if?
- active vs. passive?
- too many / too few responsibilities?
- too much control?
- Like slots (object substitution)
15Finding Responsibilities
- Object role stereotypes and purpose statements
- Use cases
- Gaps in these descriptions
- Other requirements, themes and stories
- Following what ifthenand how chains
- Relationships and dependencies between candidates
- Candidates life events
- Technical aspects of a specific software
environment - A design perspective on how things should work
16Use Roles to Generate Responsibilities
- Pushing on an objects character leads to initial
responsibilities - Ask of a service provider, what requests should
it handle? Turn around and state these as
responsibilities for doing or performing
specific services - Ask what duties does an interfacer have for
translating information and requests from one
part of the system to another (and translating
between different levels of abstraction)? - What events does a controller handle and who does
it direct?
17Stating Responsibilities
- A single responsibility is larger than an
operation or attribute - Example A DataCollector wraps operating system
resources, such as sockets or data streams,
retrieves raw data and converts it (packages it)
into one or more data records from a sensing
device. - Responsibilities Receive raw data from a sensor
or sensor group Chunks data into individual
readings - Use strong descriptions. The more explicit the
action, the stronger the statement. - Stronger verbs remove, merge, calculate, credit,
activate - Weaker verbs organize, record, process,
maintain, accept
18Technique Seeing at differentabstract levels
- We can see objects and behavior at different
levels - At the conceptual (domain) level- a set of
responsibilities - At the specification level- set of methods that
can be invoked - At the implementation level- code and data
19Class Exercise Part 2
- Arbor 2000 roles/responsibilities
20(No Transcript)
21From Analysis to Design
- Refine Domain Objects with Roles and
Responsibilities - Create Architecture
- Add Application Objects
- Add Utility Objects
- Refine Collaborations
- Refine Object Contracts
- Design Exception Handling Mechanisms
22Software Architecture
- A part of the overall Systems Architecture
- A software architecture for a program or
computing system consists of the structure or
structures of that system, which comprise
elements, the externally visible properties of
those elements, and the relationships among them
Bass 03. - The quality attributes of a software system, such
as performance, modifiability, and security, are
bound up in its software architecture. A system
with the wrong architecture will be a failure. - Software Engineering Institute (SEI)
23Architectural Views
- A view is a representation of a set of system
elements and the relations associated with them.
Views are representations of the many system
structures present simultaneously in software
systems.
24Standard Views
- Conceptual / Logical
- Process
- Physical
- Module
- User Interaction
- Security
- Performance
25Architectural Styles
- A style is a specialization of element types
(e.g., client, layer) and relationship types
(e.g., is part of, request-reply connection,
is allowed to use), along with any restrictions
(e.g., clients interact with servers but not
each other or all the software comprises layers
arranged in a stack such that each layer can only
use software in the next lower layer).
26Common Architectural Styles
- Client Server (thin/fat)
- n-tier
- Layered
- Implicit Invocation/Event-Driven
- Blackboard/Shared Memory
- Pipe and Filter
- Model View Controller
27Layered Architecture Examples
28Control Styles
- Centralized
- Dispersed
- Delegated
29Architectural Evaluation (Validation)
- How do we know if we have a good architecture?
- SAAM (Software Architecture Analysis Method)
- ATAM (Architectural Tradeoff Analysis Method)
30Class Exercise 3
- Arbor 2000 Architecture Conceptual, Process,
Physical
31 32 33 34From Analysis to Design
- Refine Domain Objects with Roles and
Responsibilities - Create Architecture
- Add Application Objects
- Add Utility Objects
- Refine Collaborations
- Refine Object Contracts
- Design Exception Handling Mechanisms
35Application Objects
- Domain Objects are familiar to the domain of
study, recognizable to customer/user. - Application Objects are familiar to developers
(UI, DB, Drivers, etc.) - Utility Objects are familiar to implementers
(Data Structures, Algorithms)
36Class Exercise
- Add Application and Utility Classes
- Create UML Class Diagram
37 38 39From Analysis to Design
- Refine Domain Objects with Roles and
Responsibilities - Create Architecture
- Add Application Objects
- Add Utility Objects
- Refine Collaborations
- Refine Object Contracts
- Design Exception Handling Mechanisms
40Collaboration
41Untrusted Collaborations
- If a collaborator cant be trusted, it doesnt
mean it is inherently more unreliable. It may
require extra precautions - Pass along a copy of data instead of sharing it
- Check on conditions after the request completes
- Employ alternate strategies when a request fails
- Check for timeliness, relevance and correctly
formed data.
42Class Exercise
- Define Trust Regions on your architecture
43From Analysis to Design
- Refine Domain Objects with Roles and
Responsibilities - Create Architecture
- Add Application Objects
- Add Utility Objects
- Refine Collaborations
- Refine Object Contracts
- Design Exception Handling Mechanisms
44Contracts
- The ways in which a given client can interact
with a given server are described by a contract.
A contract is the list of requests that a client
can make of a server. Both must fulfill the
contract the client by making only those
requests the contract specifies, and the server
by responding appropriately to those requests.
For each such request, a set of signatures
serves as the formal specification of the
contract. - Wirfs-Brock, Wilkerson Wiener
45Detailed Contracts
- Defining a precondition and a postcondition for
a routine is a way to define a contract that
binds the routine and its callers. - Bertrand Meyer, Object-Oriented
Software Construction - Meyers contracts add even more details. They
specify - Obligations required of the client
- Conditions that must be true before the service
will be requested - Obligations required of the service provider
- Conditions that must be true during and after the
execution of the service - Guarantees of service
- Defined for each method or service call
46Example A Contract For A Request That Spans A
Trust Boundary
47Class Exercise
48 49From Analysis to Design
- Refine Domain Objects with Roles and
Responsibilities - Create Architecture
- Add Application Objects
- Add Utility Objects
- Refine Collaborations
- Refine Object Contracts
- Design Exception Handling Mechanisms
50Exceptions and Reliability
51Exceptions and Design
52A range of acceptable exposure
- Loss of comfort
- Loss of discretionary money
- Loss of essential money
- Loss of life
- Alistair Cockburn
53Design for Exceptions
- Focus on making design resilient. ID key
collaborations - Develop consistent collaboration styles. Develop
an application-wide policy - Consider exceptions early!
- Develop trust regions in your design
- Develop control centers, reporting and recovery
strategies - Simplify your programming. Reduce exception
handling clutter.
54Exceptions vs. Errors
- Exceptions are deviations from the norm that we
expect. We try to get the application in a
predictable state and continue on. - Errors are when things go unexpectedly wrong.
Little can be done to recover.
55More Complications
- Consider the user steering our application.
They try to make an order, but it is partially
out of stock. - split order
- wait till all in-stock
- cancel order
- modify order
- This might potentially put system in unexpected
state. - Sometimes we dont want user steering system.
56Exception Handling Design
- There are many different ways to handle an
exception. It could be logged and re-thrown
(possibly more than once), until some object
takes corrective action. - Who naturally might handle exceptions?
- External interfacers often take responsibility
for handling faulty conditions in other systems - The initial requestor
- As a fallback, pass the buck to some object who
takes responsibility for controlling the action - Handle as close to problem as possible
57Design Guidelines
- Use exceptions to represent emergencies
- Handle exceptions as close to the problem as
possible - Separate concerns (normal vs. exception)
- DRY principle
- Get enough information so handlers can make
informed decisions - Consistency
58Design Guidelines
- Avoid creating many different exception classes.
Create only if handling expected to change
dramatically. - Pass enough information with exception so that
handlers can try to recover. - Handle exceptions dont let them fly anywhere
- Raise when the object cannot fulfill contract
59Recovery
60Strategies
- Inaction Do nothing
- Balk Admit defeat
- Guarded Suspension Suspend execution until
conditions are OK to continue - Provisional Action Pretend to perform the
action, but dont commit until conditions are OK.
61Strategies
- Recovery Perform and acceptable alternative
- Rollback Try to perform, but on failure undo
everything - Retry Repeatedly attempt, after recovering from
failed attempts - Appeal to higher authority Allow user to steer
application - Resign Minimize damage, write to log, signal
definite and safe failure. - Controller objects frequently make good handling
choices
62Exceptions to try and anticipate
- Users entering bad information or not responding
at all. - Invalid information
- Unauthorized or untimely requests
- Dropped communications
- Equipment failure
- Corrupt data, bad files
- Failure to complete in timely manner
- Critical performance errors
63Analyzing Exceptions
64Class Exercise
- Define Exception and Recovery Strategy
65Class Exercise