Design principles Flashcards

1
Q

What is a law

A

Universal truth

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

What is a principle

A

Generic best practice

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

What is a pattern

A

Generic solution to frequently occurring design problem

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

Cohesion

A

degree to which elements inside a class belong together

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

Coupling

A

degree to which two classes are connected to each other

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

Benefits of high cohesion

A

Easy to maintain, read, understand, reuse

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

Single Responsibility Principles

A

A class should have only one reason to change

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

How to ensure loose coupling

A

A class should depend on abstractions (i.e. interface), not implementation

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

Perils of high coupling

A

Ripple effects (dependency hell), hard to reuse, hard to test

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

Common coupling

A
  • Two modules have the write-access to the same
    global data
  • Uncontrolled error propagation and side effects.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Data coupling

A
  • Two modules share data through parameters or
    data structures that are used in full.
  • Example: displayTimeOfArrival(flightNumber)
    23
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Acyclic Dependencies Principle

A

the dependency graph of packages or
components should have no cycles

17
Q

Stable Dependencies Principle

A
  • packages should depend in the direction of stability
  • Instability = Ce/(Ca + Ce)
  • Ce – Efferent coupling (outgoing dependency)
  • Ca – Afferent coupling (incoming dependency)
18
Q

Abstraction

A

The interface of a component should be independent of its implementation.

19
Q

Encapsulation

A

Information hiding (i.e. private attributes)

20
Q

Modularization

A

Cohesive and loosely-coupled abstractions

21
Q

Hierarchy

A

Hierarchical organization of abstractions. Classification & generalization.

22
Q

Open-closed principle

A

Class should be open for extension and closed to modification.

23
Q

How to implement OCP

A

Define interface, extend implementation

24
Q

How to know when to use OCP

A

Bunch of if statements that check for type and call same method name

25
Q

Liskov substitution principle

A

objects of a superclass shall be replaceable with objects of its subclasses

26
Q

Interface segregation principle

A

Clients should not be forced to depend upon interfaces that they do not use. Keep interfaces small.

27
Q

Dependency inversion principle

A

depending upon interfaces or abstract classes rather than concrete implementation

28
Q

what is Aggregation

A

has-a relationship, but child can exist without parent

29
Q

what is Composition

A

has-a relationship, but child CANNOT exist without parent

30
Q

what is Association

A

has-a relationship