200 likes | 339 Views
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.
E N D
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
Coupling • Interdependency among modules • Interaction coupling through message passing
Level Type Good No Direct Coupling Data Stamp Control Common or Global Bad Content or Pathological Types of Interactive Coupling
“Single-mindedness of a module” Method cohesion Class cohesion Generalization/specialization cohesion 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
Creating the need to change another module as a result of changing one Minimize overall connascence Minimize across encapsulation boundaries Maximize within encapsulation boundary Connascence
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
Method Name: Class Name: ID: Clients (Consumers): Associated Use Cases: Description of Responsibilities: Arguments Received: Type of Value Returned: Pre-Conditions: Post-Conditions: Simple Contract Format
Syntax • No formal syntax specification • General information • Events • Message Passing • Algorithm Specification
(Get CD-info module) Accept (CD_title) {Required} Accept (CD_artist) {Required} Accept (CD_category) {Required} Accept (CD_length) Return Pseudocode Example
Summary • Translating the basic elements of OO analysis into design requires attention to prevent difficulties and conflicts in execution. • Coupling, cohesion, and connascenceare 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.