Design Principles Flashcards
Software Quality - internal factors
prob dont have to remember
- modularity
- comprehensibility (Verständlichkeit)
- cohesion (Zusammenhalt): clear responsibilities
- concision (Prägnanz): little code duplication, clear
code - correctness
Software Quality - external factors
prob dont have to remember
- Validity (ability to perform as defined)
- Robustness (ability to react appropriate to abnormal
conditions - Extensibility (ease of adapting to changes of
requirements) - Reusability (ability to serve for the construction of
different applications) - Compatibility (ease of combining elements with other
applications) - Portability (ease of transferring products to other
hardware and environments) - Efficiency (ability to use hardware resource
economically) - Ease of use (easy to learn and apply)
- Functionality (meet user expectations)
Software Quality - Main attributes
should be remembered
- Maintainability (able to evolve to meet changing
requirements of customers) - Efficiency (Does not waste system resources)
- Usability (must be usable by intended user)
- Dependability (Verlässlichkeit) (doesnt cause damage
in event of system failure, reparability,…)
How to measure software quality?
no generally accepted measure
- many different qualities
- heurisitcs that indicate canbe used -> software metrics
software metrics (how to measure quality of code)
- length of code
- cyclomatic complexity (paths through code)
- depth of conditional nesting
- weighted methods per class (depends on
sire/complexity) - depth of inheritance tree
software metrics - Pros and Cons
+ computed mechanically
+ may indicate bad design
- no notion of semantics of the code
- cannot detect coding errors
Code Metric - cyclomatic complexity
Cyclomatic complexity C (independent paths)
C := E - N + 2P
E = #Edges
N = #Nodes
P = #Connected Components
if C > 10 -> rethink design/coding
Code Measure - Class Coupling
indicates the amount of dependence between classes and packages
- Class C is coupled to D if C requires D directly or indirectly
Design Principle - Coupling done right!
give examples
Avoid tight coupling
- one change can result in cascade of changes
- classes hard to understand in isolation
- hard to reuse and low in modularity
Avoid very loose coupling
- Object-Oriented: connected objects to exchanges
messages
- need for independent objects that do all work
- may lead to unnecessary complexity
Code Measure - Cohesion
give example
measures the strength of relation among elements of a class -> all operations and data within a class should naturally belong to the concept modelled by the class
Types of Cohesion: Reasons why elements may be grouped together
undesirable
- coincidental (no meaningfull relation)
- temporal (all class elements executed together)
- sequential (one method is input to another)
- communicational (all functions/methods access same
input/output)
- functional (all elements contribute to achieve a single
well-defined responsibility) (ideal case)
ideal
Code Measure - Measuring Cohesion
LCOM
Class C, its fields F and methods M (except constructores)
undirected graph G
-> LCOM(C) #connected components (CC) of G
A high value indicates low cohesion
How to improve Cohesion?
- factor out common functionality from subclasses
- improve abstraction to summarize attributes
Responsible-Driven Design
Software object have responsibilities which are assigned to classes during object-design phase
Type of Responsibilities: doing
Performing a task - executing it themselfs - initiating action in other objects - controlling and coordination activities in other objects