Look over MVC, MVP, MVVM pattern in android.
and introduce android data binding library.
You can follow this with simple project.
https://github.com/withleedh/patternChat
References
https://realm.io/kr/news/eric-maxwell-mvc-mvp-and-mvvm-on-android/
2. 2
2
What’ Design Pattern?
A design pattern is a general reusable solution
to a commonly occurring problem.
Creational Structural Behavioral
Meaning
determines how an
object is created
Organize objects
organize, manage,
and combine the
behavior of an
object
Range
Class Factory Method Adapter(Class)
Interpreter
Template Method
Object
Abstract Factory
Builder
Prototype
Singleton
Adapter(Object)
Bridge
Composite
Decorator
Facade
Flyweight
Proxy
Command
Iterator
Mediator
Memento
Observer
State
Strategy
Visitor
3. 3
3
What’ Architecture Design Pattern?
- Similar to design pattern, but has a broader scope
View
(Composit
e)
Controller
(Strategy)
Model
(Observer)
< Representative Architecture Pattern : MVC >
5. 5
5
Classic MVC
MODEL VIEW CONTROLLER
User Event
Update CheckCheck for updates
Is Data update
needed?
Request Data update
Yes
Update Data
UI Change
No
6. 6
6
MVC in Android
MODEL
VIEW
(XML)
CONTROLLER
(Activity, Fragment)
User Event
Update CheckCheck for updates
Is Data update
needed?
Request Data update
YesUpdate Data
UI Change
No
Interact with
Get user event
Notify event
Setup View
8. 8
8
MVP Pattern in Android
VIEW PRESENTER MODEL
Request Data
depending on event
Notify event to Presenter
Get Data
Update Data
Update UI Process business logic
User Event
Notify
Send
data
View Layer doesn’t know Model anymore!!
Ask view to setup itself
10. 10
1
0
MVVM Pattern in Android
View VIEWMODEL MODEL
Request Data
depending on event
Get Data
Update Data
Update UI Process business logic
User Event
Invoke
Action
Update
Model
State
change
event
Data
Binding
Update View Itself
View Layer
doesn’t know Model
anymore!!
19. 19
1
9
Conclusion
What’s COOLEST architecture in Android?
There is no right answer for that.
It’s depend on case by case.
However, ButterKnife that we use on our app CAN BE REPLACED
with Data Binding Library.
Notas del editor
Before looking at what architectural patterns are,
Let's look briefly at what design patterns are components of an architectural pattern.
A design pattern is a pattern that can be easily used according to the situation by summarizing the structural problems that occur frequently in the process of developing a software. You can see various patterns by referring to the design pattern book of GOF which is the most influential word about design pattern.
Architectural patterns are similar to software design pattern but have a broader scope. The architectural patterns address various issues in software engineering, such as computer hardware performance limitations, high availability and minimization of a business risk. Some architectural patterns have been implemented within software frameworks.
In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design.
Architectural patterns are similar to software design pattern but have a broader scope.
If a design pattern is a solution to a problem, the architecture pattern is a solution for the overall architecture of the software.
First of all, for example, you can see that the familiar MVC architecture patterns are configured to solve one problem in the software architecture through compound patterns, that is consist of various design patterns.
View - Composite - When the controller sends a refresh request to the view, it sends an update request to the top - level view component, which is handled automatically.
Controller - Strategy - As the controller corresponds to the behavior of the view, all you have to do is change the controller to make the view behave as you want.
Model: Observer Pattern - Whenever the state of a model changes, it sends information to the observer controller and view.
So which architecture pattern is most effective for our app?
To answer that question we need to look at each architecture pattern.
We will first look at the structure of the classic MVC model, which is the ancestor of all the architectural patterns. Then, let's look at the sample code to see how the other three patterns are implemented
MODEL
The Model is an implementation of the application's domain model that includes a data model along with business and validation logic. Examples of model objects include repositories, business objects, data transfer objects (DTOs) using data base, POJO.
The view component displays information to the user. Views get data from the model. The data provided from the model can be displayed in various views, and one controller component is connected to each view.The controller component converts user input, specific events, etc. into service requests. The user interacts with the system only through the controller.
While there are advantages to being separated into three layers of model, view and controller,The disadvantage is that models and views need to know each other and therefore are less reusable.
MODEL
The Model is an implementation of the application's domain model that includes a data model along with business and validation logic. Examples of model objects include repositories, business objects, data transfer objects (DTOs) using data base, POJO.
The view component displays information to the user. Views get data from the model. The data provided from the model can be displayed in various views, and one controller component is connected to each view.The controller component converts user input, specific events, etc. into service requests. The user interacts with the system only through the controller.
While there are advantages to being separated into three layers of model, view and controller,The disadvantage is that models and views need to know each other and therefore are less reusable.
.
The MVC pattern is implemented as follows:
The model has the same role as classic MVC. Within this project, it means FireBase and chatData.
The view consists of view objects created in xml. Within this project, it means ListView and EditText.
The controller is an activity. View objects communicate with the model through activities. An activity changes its data by interacting with the model layer, finding and connecting to the view, and accessing the view directly with the changed result. As a result, the view and controller will have strong coupling, and it is difficult to test the view separately, or to test the activity itself.
The model component is still unchanged.
And in the center there is a presenter instead of a controller.
Presenter processes the actual business logic. Unlike controller, it does not directly access the view object and directly modify the view object.
Instead, it calls the main view which is a virtual view. Change the data of the view object. In other words, because the main Activity and main Presenter communicate with each other through the MainView interface by manipulating the main view, so that manipulate the views in the Android API even though presenter don’t know the actual view that working with.
So eventually if the activity implements the MainView interface, so wecan easily test the presenter logic.
The model component is still unchanged.
And in the center there is a presenter instead of a controller.
Presenter processes the actual business logic. Unlike controller, it does not directly access the view object and directly modify the view object.
Instead, it calls the main view which is a virtual view. Change the data of the view object. In other words, because the main Activity and main Presenter communicate with each other through the MainView interface by manipulating the main view, so that manipulate the views in the Android API even though presenter don’t know the actual view that working with.
So eventually if the activity implements the MainView interface, so wecan easily test the presenter logic.
The view model itself acts as a model for the view.
MVVM pattern is a pattern that allows a view to change its state by itself when it sees that the view model changes, rather than seeing the model layer and changing its data.
Again, the model has not changed.
The view does not look at the model, but instead sees the view model change and changes the data on its own.
And the view model only performs business logic.
Applying this pattern requires binding between view objects and the data model.Android provides a data binding library for data binding.Before we look at the project that implements the pattern, let's see how the Android library does the data binding.
The view model itself acts as a model for the view.
MVVM pattern is a pattern that allows a view to change its state by itself when it sees that the view model changes, rather than seeing the model layer and changing its data.
Again, the model has not changed.
The view does not look at the model, but instead sees the view model change and changes the data on its own.
And the view model only performs business logic.
Applying this pattern requires binding between view objects and the data model.Android provides a data binding library for data binding.Before we look at the project that implements the pattern, let's see how the Android library does the data binding.
To use the data binding library first, you need Android version 2.1 or later, Grades version 1.5.0 alpha 1 version or later.Just add a data binding element to the build.gradle of your app module.
됩니다.
Let's look at the data binding layout file. The root tag is replaced by layout, followed by the data element and the existing view root element.Below is the text in the text view with the addition of the observer field of the view modelYou can see how to add the method itself.
And in the main activity, we create a data binding object and connect it.
The name of the data binding class is automatically generated using the name of xml.
And in the last line, complete the binding of the view and view model by setting the view model in the binding class.
And in the main activity, we create a data binding object and connect it.
The name of the data binding class is automatically generated using the name of xml.
And in the last line, complete the binding of the view and view model by setting the view model in the binding class.
And in the main activity, we create a data binding object and connect it.
The name of the data binding class is automatically generated using the name of xml.
And in the last line, complete the binding of the view and view model by setting the view model in the binding class.
Let's look at the data binding layout file. The root tag is replaced by layout, followed by the data element and the existing view root element.Below is the text in the text view with the addition of the observer field of the view modelYou can see how to add the method itself.
Next is the view model.In the view model, you create an observable field for the view object to observe.
If you set this Observable field, the view you are viewing automatically changes its value.
Here's the hint of editText.
We did this by creating the view model for our example code,
In fact, to use the data-binding library, you can use it in your existing Android activity without creating a view model object.
So what pattern is the best?The latest architectural patterns are not the best for us.
Above all, we need to apply our architecture pattern to our current situation.
Instead, But using the Android data-binding library will enable us to develop data-binding effectively without changing our app architecture at this time.