Design Principles Flashcards

1
Q

Software Quality - internal factors

prob dont have to remember

A
  • modularity
  • comprehensibility (Verständlichkeit)
  • cohesion (Zusammenhalt): clear responsibilities
  • concision (Prägnanz): little code duplication, clear
    code
  • correctness
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Software Quality - external factors

prob dont have to remember

A
  • 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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Software Quality - Main attributes

should be remembered

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to measure software quality?

A

no generally accepted measure

  • many different qualities
  • heurisitcs that indicate canbe used -> software metrics
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

software metrics (how to measure quality of code)

A
  • length of code
  • cyclomatic complexity (paths through code)
  • depth of conditional nesting
  • weighted methods per class (depends on
    sire/complexity)
  • depth of inheritance tree
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

software metrics - Pros and Cons

A

+ computed mechanically
+ may indicate bad design

  • no notion of semantics of the code
  • cannot detect coding errors
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Code Metric - cyclomatic complexity

A

Cyclomatic complexity C (independent paths)

C := E - N + 2P
E = #Edges
N = #Nodes
P = #Connected Components

if C > 10 -> rethink design/coding

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Code Measure - Class Coupling

A

indicates the amount of dependence between classes and packages
- Class C is coupled to D if C requires D directly or indirectly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Design Principle - Coupling done right!

give examples

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Code Measure - Cohesion

give example

A
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Types of Cohesion: Reasons why elements may be grouped together

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Code Measure - Measuring Cohesion

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to improve Cohesion?

A
  • factor out common functionality from subclasses

- improve abstraction to summarize attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Responsible-Driven Design

A

Software object have responsibilities which are assigned to classes during object-design phase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Type of Responsibilities: doing

A
Performing a task
- executing it themselfs
- initiating action in other objects
- controlling and coordination activities in other 
  objects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Type of Responsibilities: knowing

A

Knowing and providing information to other objects

  • knowing private and encapsulated data
  • knowing related objects
17
Q

Design Pricipless: Collaboration of two or more classes
When to use delegation?

(give example)

A

delegation is preferable

  • less intrusive on overall design, more focused
  • can be changed/determined at runtime
18
Q

Design Pricipless: Collaboration of two or more classes
When to use inheritance?

(give example)

A
  • non dedicated syntax like extends (in Java)
  • only static calls -> no polymorphism
  • > musst extend exisiting functionality organically
19
Q

why should you programm to interfaces

give example

A
  • interfaces provide independence of functionality from
    implementation
  • does not exposes implementation details in public
    methods
  • more stable than direct implementation
  • to change implementations, sufficient to change
    constructor
20
Q

How to design field access?

give example

A

make instance fields NEVER public
-> would break information hiding

user accessor methods
-> responsible for aspects of user interface

21
Q

How to recognize and avoid God classes

give example

A
class is failing SRP
-> split and relocate responsibilities
low cohesion, non communicating classes
-> split and relocate responsibilities
uses classes with public field accessors
-> can indicate that responsibilities are located in wrong class -> redesign and relocate

=> distribute responsibilities uniformly among top-level classes

22
Q

Single Responsible design

give example

A
one responsibility per class
-> class should only have one reason to change
23
Q

what is class proliferation

A

Too many classes for the size of a given problem

24
Q

what is an object role?

A

A way to model behavior of an existing class in for example an association

(instead of class Father extends Person create an method in Person that creates an Person object called Father)