Chapter 5 - Design Principles Flashcards

1
Q

abstractions

A

a simplified representation of a given entity

Functions, classes, interfaces, and packages are classic abstractions provided by programming languages

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

What is the primary objective of software design?

A

to decompose a problem into smaller parts

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

design principles

A

guidelines for ensuring that a design meets the aforementioned properties

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

design properties

A

conceptual integrity, information hiding, cohesion, and coupling

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

Conceptual integrity

A

facilitates system usage and comprehension. When we follow this property, a user familiar with one part of a system feels comfortable using another part, as the features and user interface remain consistent.

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

Information hiding

A

offers the following advantages to a software project: Parallel development, Changeability, Comprehensibility

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

interface

A

class’s public members

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

Cohesion

A

each class should fulfill a single function or service. Specifically, all methods and attributes of a class should contribute to the implementation of the same service

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

Separation of concerns

A

recommends that a class should implement only one concern. In this context, concern refers to any functionality, requirement, or responsibility of the class.

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

Coupling

A

the strength of the connection between two modules

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

acceptable coupling

A

between class A and class B when:

  1. Class A only uses public methods from class B.
  2. The interface provided by B is stable, both syntactically and semantically. This means that the signatures of B’s public methods do not change frequently, and neither does the behavior of these methods. As a result, changes in B will rarely impact A.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

poor coupling

A

between class A and B when changes in B can easily impact A.

  1. When classes A and B share global variables or data structures, for instance, when B changes the value of a global variable used by A.
  2. When class A directly accesses a file or database used by class B.
  3. When B’s interface is not stable. For example, when the public methods of B are frequently renamed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Structural Coupling

A

between A and B occurs when a class A has an explicit reference in its code to a class B.

For example, the coupling between ParkingLot and Hashtable is structural

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

Evolutionary (or Logical) Coupling

A

between A and B occurs when changes in class B usually propagate to class A.

Thus, in Example 2, where class A depends on an integer stored in a file maintained by B, there is an evolutionary coupling between A and B. For instance, changes in the file format would have an impact on A.

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

SOLID Principles

A

Single Responsibility Principle
Open Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle

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

Single Responsibility Principle

A

This principle is an application of the idea of cohesion. It proposes that every class should have a single responsibility.

17
Q

presentation

A

a system should have presentation classes, which implement the interface with users

18
Q

business logic

A

classes perform computations directly related to the solution domain

19
Q

Interface Segregation Principle

A

The principle states that interfaces should be small, cohesive, and, more importantly, specific to each type of client. Its aim is to prevent clients from depending on interfaces with many methods they won’t use.

20
Q

Dependency Inversion Principle

A

This principle advocates that client classes should primarily depend on abstractions rather than on concrete implementations, as abstractions (i.e., interfaces) tend to be more stable than concrete implementations (i.e., classes).

21
Q

Prefer Composition Over Inheritance

A

the principle does not prohibit the use of inheritance. It merely suggests that when faced with two design solutions—one based on inheritance and the other on composition—the latter is generally preferable

22
Q

Class inheritance

A

(example: class A extends B) involves code reuse

23
Q

Interface inheritance

A

(example: interface I extends J) does not involve code reuse

24
Q

composition

A

exists when a class A contains an attribute whose type is another class B.

25
Q

Demeter Principle

A

asserts that a method’s implementation should only invoke methods:

From its own class (case 1)
From objects received as parameters (case 2)
From objects created by the method itself (case 3)
From attributes of the method’s class (case 4)

26
Q

Open-Closed Principle

A

core concept is that developers should not only implement a class, but also prepare it for future extensions and customizations. To achieve this, they can use parameters, inheritance, higher-order (or lambda) functions, and design patterns

27
Q

Liskov Substitution Principle

A

establishes rules for redefining methods in subclasses