Class and Method Design Chapter 14
Key Concepts Low-level or detailed design is critical despite libraries and components Pre-existing classes need to be understood and organized Some, if not all code, is generally still needed to instantiate new classes
DESIGN CRITERIA
Coupling Interdependency among modules Interaction coupling through message passing
Types of Interactive Coupling Level Type Good No Direct Coupling Data Stamp Control Common or Global Bad Content or Pathological
Cohesion “Single-mindedness of a module” Method cohesion Class cohesion Generalization/specialization cohesion
Types of Method Cohesion Level Type Good Functional Sequential Communicational Procedural Temporal or Classical Logical Bad Coincidental
Types of Class Cohesion Level Type Good Ideal Mixed-role Mixed-domain Worse Mixed-instance
Connascence Creating the need to change another module as a result of changing one Minimize overall connascence Minimize across encapsulation boundaries Maximize within encapsulation boundary
OBJECT DESIGN ACTIVITIES
Additional Specification First review the current set of models Sufficient but only necessary classes to solve problem No missing attributes or methods No extraneous attributes or methods Examine visibility
Signatures for each method Name of the method Parameters or arguments to pass Type of value the method will return to the calling method
Identify Opportunities for Reuse Patterns Framework Class libraries Components
Simple Contract Format Method Name: Class Name: ID: Clients (Consumers): Associated Use Cases: Description of Responsibilities: Arguments Received: Type of Value Returned: Pre-Conditions: Post-Conditions:
METHOD SPECIFICATION
Syntax No formal syntax specification General information Events Message Passing Algorithm Specification
Structured English
Pseudocode Example (Get CD-info module) Accept (CD_title) {Required} Accept (CD_artist) {Required} Accept (CD_category) {Required} Accept (CD_length) Return
Summary Translating the basic elements of OO analysis into design requires attention to prevent difficulties and conflicts in execution. Coupling, cohesion, and connascence are proposed for criteria for evaluating design. The designer will look for opportunities to optimize the design, will create constraints and contracts, and will specify methods.