Clean Architecture Flashcards

1
Q

Why architecture is important?

A

All architectures have one common goal — to manage the complexity of your application. You may not need to worry about it on a smaller project, but it becomes a lifesaver on larger ones.

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

Two key things about clean code architecture circle that represent different levels of software.

A
  • The center circle is the most abstract, and the outer circle is the most concrete. This is called the Abstraction Principle. The Abstraction Principle specifies that inner circles should contain business logic, and outer circles should contain implementation details.
  • Another principle of Clean Architecture is the Dependency Rule. This rule specifies that each circle can depend only on the nearest inward circle — this is what makes the architecture work.

The outer circle represents the concrete mechanisms that are specific to the platform such as networking and database access. Moving inward, each circle is more abstract and higher-level. The center circle is the most abstract and contains business logic, which doesn’t rely on the platform or the framework you’re using.

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

SOLID Principles define

A

Five design principles make software design more understandable, flexible and maintainable. Those principles are:

Single Responsibility: Each software component should have only one reason to change – one responsibility.

Open-closed: You should be able to extend the behavior of a component, without breaking its usage, or modifying its extensions.

Liskov Substitution: If you have a class of one type, and any subclasses of that class, you should be able to represent the base class usage with the subclass, without breaking the app.

Interface Segregation: It’s better to have many smaller interfaces than a large one, to prevent the class from implementing the methods that it doesn’t need.

Dependency Inversion: Components should depend on abstractions rather than concrete implementations. Also higher level modules shouldn’t depend on lower level modules.

Clean Architecture maximizes the use of these principles.

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

Layers of Clean Architecture

A

There are different opinions about how many layers Clean Architecture should have. The architecture doesn’t define exact layers but instead lays out the foundation. The idea is that you adapt the number of layers to your needs.

Five base layers:

  • Presentation: A layer that interacts with the UI.
  • Use cases: Sometimes called interactors. Defines actions the user can trigger.
  • Domain: Contains the business logic of the app.
  • Data: Abstract definition of all the data sources.
  • Framework: Implements interaction with the Android SDK and provides concrete implementations for the data layer.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Data layer. What for?

A

This layer provides abstract definitions for accessing data sources like a database or the internet. You’ll use Repository pattern in this layer.

The main purpose of the repository pattern is to abstract away the concrete implementation of data access. To achieve this, you’ll add one interface and one class for each model:

DataSource interface: The interface that the Framework layer must implement.
Repository class: Provides methods for accessing the data that delegate to DataSource.

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

Repository pattern and Dependency Inversion Principle

A

A Data layer which is of a higher, more abstract level doesn’t depend on a framework, lower-level layer.
The repository is an abstraction of Data Access and it does not depend on details. It depends on abstraction.

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