CS 340 Fall 2010: Section 1
CS 340 Fall 2010: Section 1
CS 340 Fall 2010: Section 1
Section 1
Design Principles
Decomposition
Making it intellectually manageable Methods Classes
Domain Driven Behavior Driven
Top-down
Produces Aggregates
Abstraction
Hiding Detail
Information Hiding
Boundary Interface/Specification Implementation
Methods Classes
Points of View
Abstraction
Classic types
Aggregation subparts Classes
Sets, properties, movement between sets Member of multiple sets Every member of set has common properties
Generalization/Specialization
All members of specialization have properties of generalization Subset semantics Requirements and Guarantees
Coupling
Too much passed in (stamp coupling) Assumptions!
Class Cohesion
Represents a single concept Use of name to detect problem
Common nouns are good
Example: Car
Class Coupling
Access to class should only occur via specified interface
Common practice is to do this via methods
All attributes are privateHide as much information as possible
Other Principles
Pay me now/Pay me later Complexity Metrics
Size
Loc Number of tokens
Eliminate duplication
Coding Style
Variable names
Programmers assumes that their abbreviation is obvious to the most casual reader NOT Minimizing typing is not a good principle It can be too long, but only if the length doesnt increase comprehension Camelback or hyphens? Basic principle: increase understanding
Coding Style
Method names
Active verb Direct object No conjunctions (indicates poor cohesion)
Coding Style
Comments
Self-commenting code Dont put in echo comments Use for class description, domain, invariants, domain implementation, method description, pre- and post- conditions. Describe assumptions Help reader understand why you made difficult decisions