Tell about the design patterns used in Android application development.
sobes.tech AI
Answer from AI
MVC (Model-View-Controller): Divides the application into three interconnected parts:
- Model: Business logic and data.
- View: Data presentation.
- Controller: Handles user input and updates Model and View.
MVP (Model-View-Presenter): An improved version of MVC for Android. The Presenter acts as an intermediary between the Model and the View. The View does not have direct access to the Model.
MVVM (Model-View-ViewModel): Based on data binding. The ViewModel contains data and presentation logic without referencing the View. The View observes changes in the ViewModel.
Clean Architecture: Separates the application into layers (Domain, Data, Presentation) with clear dependencies and rules.
Singleton: Ensures that a class has only one instance.
Factory Method: Provides an interface for creating objects in a superclass, allowing subclasses to alter the type of objects created.
Observer:
Allows an object to notify dependent objects of state changes. Often used with LiveData or Flow.
Adapter:
Enables classes with incompatible interfaces to work together. Used, for example, for binding data to RecyclerView.
Builder: Allows the creation of complex objects step by step.
Decorator: Dynamically adds new functionality to an object by wrapping it.