Design principles Flashcards
1
Q
What is a law
A
Universal truth
2
Q
What is a principle
A
Generic best practice
3
Q
What is a pattern
A
Generic solution to frequently occurring design problem
4
Q
Cohesion
A
degree to which elements inside a class belong together
5
Q
Coupling
A
degree to which two classes are connected to each other
6
Q
Benefits of high cohesion
A
Easy to maintain, read, understand, reuse
7
Q
Single Responsibility Principles
A
A class should have only one reason to change
8
Q
How to ensure loose coupling
A
A class should depend on abstractions (i.e. interface), not implementation
9
Q
Perils of high coupling
A
Ripple effects (dependency hell), hard to reuse, hard to test
10
Q
Content coupling
A
- One module(e.g., class) uses the code/data from
another module. - Example: class A refers to local data of class B!
- Violates information hiding principle of OOP.
11
Q
Common coupling
A
- Two modules have the write-access to the same
global data - Uncontrolled error propagation and side effects.
12
Q
External coupling
A
- Two modules depend on a module external to
the software or a specific hardware. - Example: protocol, external file, and device
format.
13
Q
Control coupling
A
- One module A controls the flow of another
module B by passing control parameters (e.g.,
what-to-do flag) - Module A must know the internal structure of B.
- Example: A sends comparison(a,b) to sort() in B
14
Q
Stamp coupling
A
- Module A passes the whole data structure to B,
but only a fraction of it is used. - Example: printCustomerBilling(Customer)
15
Q
Data coupling
A
- Two modules share data through parameters or
data structures that are used in full. - Example: displayTimeOfArrival(flightNumber)
23