CS 340 Fall 2010: Section 1

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 11

CS 340 Fall 2010

Section 1

Design Principles

Decomposition
Making it intellectually manageable Methods Classes
Domain Driven Behavior Driven

Top-down
Produces Aggregates

Bottom-up (anti-decomposition?) Hypo- and Hyper- decomposition

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

Method Coupling and Cohesion


Methods
Cohesion
Does one thing to one type of object
From an abstract point of view

Look at name to determine if it might have cohesion problems.


If name had conjunctions, that is often bad

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

Fuzzy Names Bad


Example: Stuff

Collection names are problematic


Example: Math class Language Issue classes used as packages

Primitive obsession usually a problem


Can be abstract

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

Inappropriate information exposed:


Public methods Assumptions, especially about implementation
Set vs. HashSet

Java Beans problem


Entire domain implementation is exposed

Other Principles
Pay me now/Pay me later Complexity Metrics
Size
Loc Number of tokens

McCabes Cyclomatic Number

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)

Consistency Indentation Whitespace


Use wisely Contradicts bad smell

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

You might also like