0% found this document useful (0 votes)
32 views

MVC Design Pattern

The document discusses the Model-View-Controller (MVC) architecture used in Android applications. MVC separates applications into three layers - the model layer contains application data and logic, the view layer handles visual presentation and user interaction, and the controller layer coordinates data flow between the model and view layers. The controller responds to user input from the view to update the model, and the model notifies the view to change on updates. An example counter app is provided to illustrate how MVC components work together.

Uploaded by

Visal Nann
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

MVC Design Pattern

The document discusses the Model-View-Controller (MVC) architecture used in Android applications. MVC separates applications into three layers - the model layer contains application data and logic, the view layer handles visual presentation and user interaction, and the controller layer coordinates data flow between the model and view layers. The controller responds to user input from the view to update the model, and the model notifies the view to change on updates. An example counter app is provided to illustrate how MVC components work together.

Uploaded by

Visal Nann
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Model-View-Controller

Department of IT Engineering

Lecturer: Kor Sokchea

Java Programming
Model-View-Controller

Model

Updates
Manipulates

View Controller

Sees uses
User

Java Programming | Kor Sokchea ([email protected])


Model-View-Controller
 Android applications are designed around an architecture called Model-View-Controller
(MVC)
Model

Controller

View

Java Programming| Kor Sokchea ([email protected])


Model Object
 A model object holds application’s data and “business logic”
 Model class are typically designed to model the things your app is concerned with:
• A user
• A Product in a store
• A photo on a sever
 Model objects have no knowledge of the user interface
 The main purpose is holding and managing data
 In Android applications, model classes are generally custom classes you create
 All of the model objects in your application compose its model layer

Java Programming | Kor Sokchea ([email protected])


View Object
 View objects know:
 How to draw themselves on the screen
 How to respond to user input like touches
 A simple rule of thumb is that if you can see it on screen, then it is a view
 Android provides a wealth of configurable view classes
 You can also create custom view classes
 An application’s view objects make up its view layer
 In android, View layer consists of the widgets that are inflated from activity_main.xml

Java Programming | Kor Sokchea ([email protected])


Controller Object
 Controller objects tie the view and model objects together
 Controller objects contain “application logic”
 Controllers are designed:
• To respond to various events triggered by view objects
• To manage the flow of data to and from model objects and the view layer
 In Android, a controller is typically a subclass of Activity, Fragment, or Service

Java Programming | Kor Sokchea ([email protected])


MVC Flow with User Input

Java Programming | Kor Sokchea ([email protected])


MVC Example
Counter
Model _mCount

mCounterObj
Controller
CounterActivity
_mCurrentCount;

View (layout)
countTextView countButton

TextView Button

Java Programming | Kor Sokchea ([email protected])

You might also like