You are on page 1of 12

Subsystems

• Groups of classes that collaborate among themselves to support a set


of contracts

• Goal: simplify patterns of communications

1
What is a subsystem?
• Problem: Collaboration graphs get very complicated. (Too many lines.)
• Solution: Collect classes together to form subsystems.
• Subsystem behaves like a class: supports services to outside via
contracts.
• Subsystems are not super classes.
• Subsystems are not “just a bunch of classes.”
• Subsystems should provide a good abstraction.

2
Subsystem graph
Name of 1 • All contracts supported by
subsystem things inside a subsystem for
1
things outside the subsystem.
Name of class • Use the subsystem to simplify
the design.
2 Name of
superclass

Name of Name of
subclass subclass

3
Identification of Subsystem
• Draw collaboration graph (use white board).
• Look for strongly coupled classes.
• Look for ways to simplify your description of the system.
• Look for clean separations.
• Look for good abstractions.

4
Simplify:
1- Minimize number of collaborations a class has with other classes
• Class should collaborate with as few other classes as possible. (Why?)
• Heuristic: centralize communications
2- Minimize number of classes & subsystems to which a subsystem
delegates
• Keep the number of classes inside the subsystem that support subsystem
contracts to a minimum
• Again, centralize communications into and out of the subsystem
3- Minimize number of contracts supported by a class or subsystem
5
Example 1: Inventory Subsystem

Inventory Transaction
Accounting
Item Log
3 Subsystem
1 2

Cash Warehouse
Register

6
Example
Inventory Transaction
Item Log Accounting
3
2 Subsystem
1

Cash Warehouse
Register

7
Example
Inventory Simplify Inventory
Transaction Accounting
Item Subsystem
Log Subsystem
2 3 4
1

Manager
Inventory
4 Cash Register Warehouse
Subsystem
4

Warehouse
Cash Register
8
• Too many contracts in one place indicate too much intelligence
concentrated in one place: split the functionality between two or
more classes.
• Re-examine the collaboration patterns

If you have to redesign ...


• Redraw the graphs.
• Re-examine the collaboration patterns
• Walk through scenarios (all of them)
• Verify that things are simpler, have improved cohesion and reduced coupling.
9
Example 2: Contracts of ATM
1. Account: Access and modify balance
2. Account: commit result to database
3. Display: Display information
4. Form: Get numeric value from user
5. Input Device: accept user input
6. Menu: Get user selection
7. Output Device: output to the user
8. Transaction: execute financial transaction
9. User Message: display message and wait
10
Collaboration Graph Simple Graph
Minimize Collaborations 25 → 6 main Collaborations
Account Minimize Classes 12 → 3 Subsystems
1 2 Minimize Contracts 9 → 4 main contracts

Create and initiate


Balance Deposit Withdrawal Transfer transactions
Display main menu
Transaction Eject receipt
8 Eject bank card
Financial 8
Display Dev 3 Subsystem
4
Form
Input Dev ATM
6 Menu
5 Simplify
BCR 4 6 9
User User Interface
9
Msg Subsystem
7
Output Dev
ATM User Interaction
11
Redesigned Graph Financial
Subsystem

Display Dev 3 4
Form
Input Dev
6 Menu
5
BCR
User
9
Msg
7
Output Dev
ATM User Interaction
12

You might also like