Clean architecture Flashcards

1
Q

What is the solid acronym for?

From which level of design is it part?

A
S: single responsibility principle
O: open-close principle
L: Liskov substitution principle
I: the interface segregation principle
D: The dependency inversion principle

Its part of the design principle. (the class level)

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

What is the Single responsibility principle?

A

Each software module has one, and only one, reason to change.

For example, a class book should only keep the information about the book. We should keep a separate class for printing the content of the book.

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

What is the Open-closed principle?

A

For software systems to be easy to change, they must be designed to allow the behaviour of those systems to be changed by adding new code, rather than changing existing code. In other words, you can extend the code but not modify the original code. The example is if we need to add new functionality we should extend the class and not modify the class. By extending the class we are certain the original class will not be affected.

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

What is the Liskov Substitution principle?

A

If S is a subtype of T, then objects of type T in a program may be replaced with objects of type S without altering any of the desirable properties of that program.

In other words, the children function need to accept the same input return the same output as the parent class. You can extend the accepted input and that it.

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

What is the interface segregation principle?

A

No code should be forced to depend on methods it does not use. Often a parent class force it, children, to implement a function. If the children need to implement a function it will never use, the parent class should be split into multiple smaller classes.

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

What is the dependency inversion principle?

A

The code that implements high-level policy should not depend on the code that implements low-level details. Rather, details should depend on policies. The example given here does not create the class within the high-level class itself. When you initiate the instance you input the lower-level classes.

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

What are the three principles of component cohesion?

From which level of design is it part?

A

• REP: The Reuse/Release Equivalence Principle
• CCP: The Common Closure Principle
• CRP: The Common Reuse Principle
Its from the Component principle level (link between the different package and modules).

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

What is the Reuse/Release equivalence principle (REP) (3points)?

A
Three important detail of REP:
(no copy pasting, versioning, package unit)
1) code should not be reused by copying it from one class and pasting it into another.
2) Effective reuse requires tracking of releases from a change control system. The author of a library needs to identify releases with numbers or names of some sort. This allows users of the library to identify different versions. This requires the use of some kind of release tracking system.
3) The package is the effective unit of reuse and release. The package should be self-sustained. In other words, it does not depend on any other package.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the common closure principle (CCP)?

A

The CCP states that packages should only have one reason to change.

Another way to look at this is: Gather into components those classes that change for the same reasons and at the same time. Separate into different components those classes that change at different times for different reasons. This is the Single responsibility principle restated for components

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

What is the common reuse principle (CRP)?

A

The CRP states that classes that tend to be reused together belong in the same package together.

It is a way of helping to decide which classes belong in which package.
When depending on a package, one wants to make sure that the classes are inseparable and interdependent, which is also handy when pulling classes that do not belong in the package.

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

When many developers work on the same project, their codes often contradict each other. What is a solution to this problem?

A

One solution is to split the project into many different components. Each component will have a release version therefore everyone using the component can return back to a previous version if part of the component stops working as expected.

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

What is the number 1 rule of component coupling?

A

The dependency structure of the components cannot contain any cycle Such as a->b->c->a.

Otherwise, every developer working on a,b and c will have to coordinate their release together.

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

When cycles inevitably occur in component coupling. What are the two techniques used to break them?

A

1) apply the Dependency Inversion Principle (DIP). Which mean inverted one of the dependency.
2) Create a new component that both components depend on.

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

What is a counterintuitive fact about component coupling and top-down design?

A

The component structure cannot be entirely designed from the top down. but it rather evolves as
the system grows and changes.

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

What is the goal of the stability dependency principle (SDP)?

A

Design your software in such a way that any given component depends on other components that are more stable than it is.

In other words, the dependencies within a component architecture should point toward increasing stability. This will ensure that components that need to change frequently will be easy to change and that the stable components that others depend on will not change nearly as often.

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

What is the difference between a volatile component and a stable one?

A

A volatile component change easily and a stable one does not change easily.

17
Q

What is the easiest way to make a component harder to change?

A

To add a lot of dependencies to that component.

18
Q

What is the difference between a responsible component and an irresponsible component?

A

The responsible component has other components being dependent upon itself and cannot change easily.
The irresponsible component has no other component that depends on it. But it depends on other components.

19
Q

If a component depends on a volatile component (change often), what is one technique you could use to prevent problems from occurring?

A

Break the relationship between the two-component by creating a third component.