Скачать презентацию Subsystems CS 4311 Wirfs Brock et al Скачать презентацию Subsystems CS 4311 Wirfs Brock et al

006378b7c2c9ed3b05c9e3c5f21ce34d.ppt

  • Количество слайдов: 30

Subsystems CS 4311 Wirfs Brock et al. , Designing Object-Oriented Software, Prentice Hall, 1990. Subsystems CS 4311 Wirfs Brock et al. , Designing Object-Oriented Software, Prentice Hall, 1990. (Chapter 7) 1

Outline Subsystems: what and why? n Subsystem documentation n ¨ Subsystems cards ¨ Collaboration Outline Subsystems: what and why? n Subsystem documentation n ¨ Subsystems cards ¨ Collaboration graphs n Guidelines for defining subsystems 2

Steps for Producing Initial Designs n Identify ¨ Classes ¨ Responsibilities ¨ Collaborations n Steps for Producing Initial Designs n Identify ¨ Classes ¨ Responsibilities ¨ Collaborations n Analyze ¨ Class hierarchies ¨ Contracts ¨ Collaboration graphs 3

Problem n Collaboration graphs get very complicated. ¨ Too n n many lines (i. Problem n Collaboration graphs get very complicated. ¨ Too n n many lines (i. e. , interactions or communications) Designs become incomprehensible. How to simply the design, esp. patterns of communications? 4

Solution n n Need an abstraction tool to provide macro views Collect classes together Solution n n Need an abstraction tool to provide macro views Collect classes together to form subsystems that ¨ Behave like a class. ¨ Support services to outside via contracts. 5

What Are Subsystems? n n Groups of classes that collaborate among themselves to support What Are Subsystems? n n Groups of classes that collaborate among themselves to support a set of contracts Goal: To simplify patterns of communications 6

What Are Subsystems? (Cont. ) n n Subsystems are not super classes. Subsystems are What Are Subsystems? (Cont. ) n n Subsystems are not super classes. Subsystems are not “just a bunch of classes. ” Subsystems should provide a good abstraction. Subsystems should provide a clearly defined interface, called subsystem contracts. 7

Subsystem Contracts 1 Printing Subsystem n 1 ¨ by things inside a subsystem ¨ Subsystem Contracts 1 Printing Subsystem n 1 ¨ by things inside a subsystem ¨ for things outside the subsystem. Print Server 2 Ink. Jet Printer Laser Printer All contracts supported n Delegation of contracts 8

Subsystem Cards for Documenting Subsystems n n n Write the subsystem name at the Subsystem Cards for Documenting Subsystems n n n Write the subsystem name at the top List all classes in the subsystem Include ref. to the subsystem’s position in the collaborations graphs Describe the purpose of the subsystem List contracts for which it is a server For each contract, identify the class or subsystem to which the contract is delegated 9

Subsystem Cards (Cont. ) Subsystem: Drawing Subsystem Classes: Control Point, Drawing Element, … Collaborations Subsystem Cards (Cont. ) Subsystem: Drawing Subsystem Classes: Control Point, Drawing Element, … Collaborations Graphs: see Figure 4 -6 Description: Responsible for displaying and maintaining the contents of the drawing… Contracts 1. Display itself Server: Drawing 2. Access and modify the contents of a drawing Server: Drawing 3. Modify the attributes of a Drawing Element Server: Control Point 10

How to Identify Subsystems? n Bottom Up ¨ Start with classes and responsibilities ¨ How to Identify Subsystems? n Bottom Up ¨ Start with classes and responsibilities ¨ Identify collaborations ¨ Partition the classes based on patterns of collaborations ¨ This approach is useful when managing the complexity as a system grows. 11

Subsystem Identification n n Draw collaboration graph (use white board). Look for strongly coupled Subsystem Identification n n 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. 12

How to Identify Subsystems? n Top down ¨ Look at high level functions of How to Identify Subsystems? n Top down ¨ Look at high level functions of system ¨ Look at data sources and uses ¨ Look at supporting technologies ¨ Partition to manage complexity and reduce coupling ¨ This approach may be useful when managing the complexity imposed by initial specification. 13

Guidelines for Simplifying Interactions n n n Minimize number of collaborations a class has Guidelines for Simplifying Interactions n n n Minimize number of collaborations a class has with other classes or subsystems. Minimize number of classes and subsystems to which a subsystem delegates. Minimize number of contracts supported by a class or subsystem. 14

G-1: Minimize Number of Collaborations n n Class should collaborate with as few other G-1: Minimize Number of Collaborations n n Class should collaborate with as few other classes and subsystems as possible. (Why? ) Heuristic: Centralize communications 15

Example File 3 File 1 1 Printing Subsystem 1 1 Print Server 2 3 Example File 3 File 1 1 Printing Subsystem 1 1 Print Server 2 3 Color Printer Printing Subsystem Print Server 2 Printer Laser Printer 3 Color Printer Laser Printer 16

G-2: Minimize Delegations of Subsystem Contracts n n Keep the number of classes inside G-2: Minimize Delegations of Subsystem Contracts n n Keep the number of classes inside the subsystem that support subsystem contracts to a minimum Again, centralize communications into and out of the subsystem 17

G-3: Minimize Number of Contracts n n Too many contracts in one place indicate G-3: Minimize Number of Contracts n n 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 18

Example Cash Register 1 Inventory Item Warehouse 2 Transaction Log 3 Accounting Subsystem 19 Example Cash Register 1 Inventory Item Warehouse 2 Transaction Log 3 Accounting Subsystem 19

Example Cash Register 1 Inventory Item Warehouse 2 Transaction Log 3 Accounting Subsystem 20 Example Cash Register 1 Inventory Item Warehouse 2 Transaction Log 3 Accounting Subsystem 20

Example Refined Cash Register Inventory Subsystem Warehouse 1 2 3 Inventory Item Transaction Log Example Refined Cash Register Inventory Subsystem Warehouse 1 2 3 Inventory Item Transaction Log Accounting Subsystem 21

Example Refined Further Cash Register Warehouse 4 Inventory Subsystem 4 Inventory Manager 1 Inventory Example Refined Further Cash Register Warehouse 4 Inventory Subsystem 4 Inventory Manager 1 Inventory Item 2 Transaction Log 3 Accounting Subsystem 22

If You Have to Redesign. . . n n Redraw the graphs. Re-examine the If You Have to Redesign. . . n n 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 23

ATM Example: Contracts 1. 2. 3. 4. 5. 6. 7. 8. 9. Account: Access ATM Example: Contracts 1. 2. 3. 4. 5. 6. 7. 8. 9. Account: Access and modify balance Account: commit result to database Display: Display information Form: Get numeric value from user Input Device: accept user input Menu: Get user selection Output Device: output to the user Transaction: execute financial transaction User Message: display message and wait 24

Collaboration Graph Account 1 Balance Transaction Display Device 2 Deposit Withdrawal Transfer 8 3 Collaboration Graph Account 1 Balance Transaction Display Device 2 Deposit Withdrawal Transfer 8 3 4 Input Device Form 6 Menu 9 5 User Message BCR Output Device 7 ATM User Interaction 25

Refining Account 1 Balance Transaction Display Device 2 Deposit Withdrawal Transfer 8 3 4 Refining Account 1 Balance Transaction Display Device 2 Deposit Withdrawal Transfer 8 3 4 Input Device Form 6 Menu 9 5 User Message BCR Output Device 7 ATM User Interaction 26

Simplified Graph Financial Subsystem 8 Display Device 3 4 Input Device 6 5 Form Simplified Graph Financial Subsystem 8 Display Device 3 4 Input Device 6 5 Form Menu BCR 9 User Message Output Device 7 ATM User Interaction 27

Even More Simplified Graph Financial Subsystem 8 ATM 3 4 5 6 7 User Even More Simplified Graph Financial Subsystem 8 ATM 3 4 5 6 7 User Interface Subsystem 9 Too many contracts? 28

Rework n n n Rework your design. If it isn’t changing, you’re not working. Rework n n n Rework your design. If it isn’t changing, you’re not working. Do not change just to change, but change based on recognition of better design. Take pride in your work. 29

Group Work and Assignment n n Group work (see handout) Subsystems for the project Group Work and Assignment n n Group work (see handout) Subsystems for the project ¨ Due: Mar. ? , 2013 ¨ Leader: Architect ¨ Contents n n Class diagram showing all classes and their relationships (inheritance and associations) Contracts by refining your CRC cards Subsystems by grouping classes and identifying subsystem contracts (subsystem cards) Collaboration graphs 30