Clean_Architecture_Interview_QA
Clean_Architecture_Interview_QA
Clean Architecture is a design pattern that separates code into layers with clear responsibilities. It improves
1) Presentation 2) Domain 3) Data 4) Core (optional). Each layer has a distinct role.
Contains Entities, Use Cases, and Repository Interfaces. It holds business logic and is independent of
external dependencies.
To keep the domain independent and make it easy to replace or modify data sources without affecting
business logic.
A plain Dart class representing a business object, free from dependencies like Dio or JSON handling.
It defines a business operation (e.g., GetAllProducts) and resides in the domain layer.
To decouple domain logic from actual data sources and support mocking in tests.
Directly interacts with remote APIs or local storage. Converts data to models.
11. What's the difference between a remote and local data source?
Remote connects to web APIs, local uses local storage (e.g., Hive, SQLite).
Using tools like GetIt for registering use cases, BLoCs, and services for inversion of control.
13. Why is the domain layer not allowed to depend on data or presentation?
Fat UI, tight coupling, using Dio in BLoC, or skipping proper separation of layers.
Use a mock class and simulate return values using packages like mocktail or Mockito.
16. Can you explain the data flow from UI to data source?
UI -> BLoC -> Use Case -> Repository -> Data Source -> API -> back to UI via entity.
Entities are domain objects, Models are used for JSON parsing and API logic in the data layer.
BLoC handles UI logic and state. Use case executes domain logic (e.g., GetAllProducts).
Because it implements domain interfaces and converts models to entities, not vice versa.