Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Chapter 11 Component-Level Design. 2 What is a Component? OMG Unified Modeling Language Specification [OMG01] defines a component as “… a modular, deployable,

Similar presentations


Presentation on theme: "1 Chapter 11 Component-Level Design. 2 What is a Component? OMG Unified Modeling Language Specification [OMG01] defines a component as “… a modular, deployable,"— Presentation transcript:

1 1 Chapter 11 Component-Level Design

2 2 What is a Component? OMG Unified Modeling Language Specification [OMG01] defines a component as “… a modular, deployable, and replaceable part of a system that encapsulates implementation and exposes a set of interfaces.”

3 3 OO view of Component Design A component contains a set of collaborating classes, Basic design concept Begin with the analysis model Elaborate Analysis classes Infrastructure classes Example Print shop

4 4 OO Component PrintJob computeJob initiateJob i i l i ii i l passJobto Production() design component numberOfPages numberOfSides paperType magnification productionFeatures PrintJob computeJobCost() passJobtoPrinter() analysis class

5 5 Conventional view of Component Design Component from conventional view processing logic the internal data structures implementing processing logic an interface that enables the component to be invoked and data to be passed to it Basic design concept Begin with the analysis model, usually DFD Transform DFD into structure chart Elaborate each module in structure chart Control component Problem domain component Example Print Shop

6 6 Structure Chart

7 7 Conventional Component

8 8 Basic OO-Design Principles The Open-Closed Principle (OCP). “A module [component] should be open for extension but closed for modification. Example: Detector class for the SafeHome security function

9 9 Basic OO-Design Principles (cont.) The Liskov Substitution Principle (LSP). “Subclasses should be substitutable for their base classes. Dependency Inversion Principle (DIP). “Depend on abstractions. Do not depend on concretions.” The Interface Segregation Principle (ISP). “Many client-specific interfaces are better than one general purpose interface. Example – FloorPlan class for the SafeHome Sensor management may be different from and camera management Need specific operations for surveillance interface

10 10 Basic OO-Design Principles (cont.) Additional packaging principles The Release Reuse Equivalency Principle (REP). “The granule of reuse is the granule of release.” component level or package level The Common Closure Principle (CCP). “Classes that change together belong together.” Class should be packaged cohesively The Common Reuse Principle (CRP). “Classes that aren’t reused together should not be grouped together.”

11 11 Guidelines for OO-Component Design Components Naming conventions should be established for components that are specified as part of the architectural model and then refined and elaborated as part of the component-level model For problem domain component: use meaningful name for all stakeholders viewing the architectural model Example: class FloorPlan For infrastructure component: Use implementation-specific name Example: manageList()

12 12 Guidelines for OO-Component Design (cont.) Interfaces Interfaces provide important information about communication and collaboration (as well as helping us to achieve the OCP) Recommendation for simplified UML component diagram Use lollipop representation when diagrams grow complex Interfaces should flow from the left-hand side of the component box Show only those interfaces relevant to the component

13 13 Guidelines for OO-Component Design (cont.) Dependencies and Inheritance It is a good idea to model dependencies from left to right and inheritance from bottom (derived classes) to top (base classes) Represent component interdependencies through interfaces

14 14 Cohesion Conventional view: the “single-mindedness” of a module OO view: cohesion implies that a component or class encapsulates only attributes and operations that are closely related to one another and to the class or component itself Levels of cohesion Functional Layer Communicational Sequential Procedural Temporal Utility: Statistics class The most basic and important

15 15 Example–Layer Cohesion

16 16 Coupling Conventional view: The degree to which a component is connected to other components and to the external world OO view: A qualitative measure of the degree to which classes are connected to one another Level of coupling Content: violate information hiding Common: invoke global variable Control: A() invoke B() passing a flag Stamp: a class B is declared as type of operation in A Data: passing long strings of arguments Routine call Type use: a component A use data type defined in B Inclusion or import External

17 17 Component Level Design-I Step 1. Identify all design classes that correspond to the problem domain. Step 2. Identify all design classes that correspond to the infrastructure domain. Step 3. Elaborate all design classes that are not acquired as reusable components. Step 3a. Specify message details when classes or component collaborate. ExampleExample Step 3b. Identify appropriate interfaces for each component. Check cohesion and apply refactoring.refactoring Step 3c. Elaborate attributes and define data types and data structures required to implement them. ExampleExample Step 3d. Describe processing flow within each operation in detail. Use pseudocode or UML activity diagram.activity diagram

18 18 Component-Level Design-II Step 4. Describe persistent data sources (databases and files) and identify the classes required to manage them. Step 5. Develop and elaborate behavioral representations for a class or component. Use UML statechart diagram.statechart diagram Step 6. Elaborate deployment diagrams to provide additional implementation detail. Specific hardware, operating system Step 7. Factor every component-level design representation and always consider alternatives.

19 19 Collaboration Diagram

20 20 Refactoring

21 21 Attribute Type Defined UML type declaration paperWeight: string = ‘A’ {contains 1 of 4 values – A, B, C, or D}

22 22 Activity Diagram computePaperCost(weight, size, color): numeric

23 23 Statechart Transition form: Event-name (parameter-list) [guard-condition]/action expression written in Object ConstraintLanaguage (OCL) Example: for jobCostAccepted event customer self.authorizationAuthority = ‘yes’

24 24 Object Constraint Language (OCL) Complements UML by allowing a software engineer to use a formal grammar and syntax to construct unambiguous statements about various design model elements Simplest OCL language statements are constructed in four parts: (1) a context that defines the limited situation in which the statement is valid; (2) a property that represents some characteristics of the context (e.g., if the context is a class, a property might be an attribute) (3) an operation (e.g., arithmetic, set-oriented) that manipulates or qualifies a property, and (4) keywords (e.g., if, then, else, and, or, not, implies) that are used to specify conditional expressions.

25 25 OCL Example context PrintJob::validate(upperCostBound : Integer, custDeliveryReq : Integer) pre: upperCostBound > 0 and custDeliveryReq > 0 and self.jobAuthorization = 'no' post: if self.totalJobCost <= upperCostBound and self.deliveryDate <= custDeliveryReq then self.jobAuthorization = 'yes' endif

26 26 Algorithm Design the closest design activity to coding the approach: review the design description for the component use stepwise refinement to develop algorithm use structured programming to implement procedural logic use ‘formal methods’ to prove logic

27 27 Stepwise Refinementopen walk to door; reach for knob; open door; walk through; close door. repeat until door opens turn knob clockwise; if knob doesn't turn, then take key out; take key out; find correct key; find correct key; insert in lock; insert in lock; endif pull/push door move out of way; end repeat

28 28 Algorithm Design Model represents the algorithm at a level of detail that can be reviewed for quality options: graphical (e.g. flowchart, box diagram) pseudocode (e.g., PDL)... choice of many programming language decision table conduct walkthrough to assess quality

29 29 Structured Programming for Procedural Design uses a limited set of logical constructs: sequence conditional — if-then-else, select-case — if-then-else, select-case loops — do-while, repeat until — do-while, repeat until leads to more readable, testable code important for achieving high quality, but not enough can be used in conjunction with ‘proof of correctness’

30 30 A Structured Procedural Design

31 31 Decision Table

32 32 Program Design Language (PDL)

33 33 component alarmManagement; The intent of this component is to manage control panel switches and input from sensors by type and to act on any alarm condition that is encountered. set default values for systemStatus (return value), all data items initialize all system ports and reset all hardware check controlPanelSwitches (cps) if cps = “test” then invoke alarm set to “on” if cps = “alarmOff” then invoke alarm set to “off”. default for cps = none reset all singalValues and switches do for all sensors invoke checkSensor procedure returning singalValue if signalValue > bound [alarmType] then phone.message = message [alarmType] set alarmBell to “on” for alarmTimeSeconds set system status = “alarmCondition” parbegin invoke alarm procedure with “on”, alarmTimeSeconds; invoke phone procedure set to alarmType, phoneNumber parend else skip endif enddofor end alarmManagement component alarmManagement; The intent of this component is to manage control panel switches and input from sensors by type and to act on any alarm condition that is encountered. set default values for systemStatus (return value), all data items initialize all system ports and reset all hardware check controlPanelSwitches (cps) if cps = “test” then invoke alarm set to “on” if cps = “alarmOff” then invoke alarm set to “off”. default for cps = none reset all singalValues and switches do for all sensors invoke checkSensor procedure returning singalValue if signalValue > bound [alarmType] then phone.message = message [alarmType] set alarmBell to “on” for alarmTimeSeconds set system status = “alarmCondition” parbegin invoke alarm procedure with “on”, alarmTimeSeconds; invoke phone procedure set to alarmType, phoneNumber parend else skip endif enddofor end alarmManagement Example PDL


Download ppt "1 Chapter 11 Component-Level Design. 2 What is a Component? OMG Unified Modeling Language Specification [OMG01] defines a component as “… a modular, deployable,"

Similar presentations


Ads by Google