CSE687 - Lecture #2 Design Note
Prime Directives (PD)
Revised: 31 January 2007
Prime Directives (PD):
-
No surprises
A component, e.g., a module or class should act the way it looks like it should act.
The interface should describe what it does in a way that any competent developer
can understand.
C++ provides operator notation so a class can support syntax that fits the
class's model, e.g., matrix, string, ...
-
Maximize Cohesion
Things that are grouped together should be related in function and be focused
on a single objective.
C++ classes have a fairly low syntactic overhead, so it is practical to create
small cohesive classes.
-
Minimize Coupling
When a component changes, everything it’s coupled to may need to change.
Try to couple only to interface, not implementation.
Try to minimize “assumption” coupling and “need to know” coupling as well as
data coupling.
References:
C++ supports passing and returning references from functions. This greatly
reduces the need to pass pointers into and out of functions, making them
much less susceptible to client miss-use.
Polymorphism:
C++ supports dynamic binding with virtual functions, providing strong support
for building loosely coupled systems. The client of a base class need know only
the protocol provided by the base and need not know the details that distinguish
one derived class from another.
Examples:
-
The tok module, in
semi project folder is responsible for
extracting tokens from a stream.
-
tok contains three classes:
-
codeDelimiter is responsible for defining delimiters when parsing C or C++ code.
-
xmlDelimiter is responsible for defining delimiters when parsing xml.
-
toker is responsible for extracting tokens.