Clean architecture Flashcards
What is the solid acronym for?
From which level of design is it part?
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)
What is the Single responsibility principle?
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.
What is the Open-closed principle?
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.
What is the Liskov Substitution principle?
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.
What is the interface segregation principle?
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.
What is the dependency inversion principle?
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.
What are the three principles of component cohesion?
From which level of design is it part?
• 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).
What is the Reuse/Release equivalence principle (REP) (3points)?
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.
What is the common closure principle (CCP)?
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
What is the common reuse principle (CRP)?
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.
When many developers work on the same project, their codes often contradict each other. What is a solution to this problem?
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.
What is the number 1 rule of component coupling?
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.
When cycles inevitably occur in component coupling. What are the two techniques used to break them?
1) apply the Dependency Inversion Principle (DIP). Which mean inverted one of the dependency.
2) Create a new component that both components depend on.
What is a counterintuitive fact about component coupling and top-down design?
The component structure cannot be entirely designed from the top down. but it rather evolves as
the system grows and changes.
What is the goal of the stability dependency principle (SDP)?
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.