android and model / view / controller. slide 2 design patters common solutions to programming...
TRANSCRIPT
![Page 1: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/1.jpg)
ANDROID AND MODEL / VIEW /
CONTROLLER
![Page 2: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/2.jpg)
Slide 2
Design Patters Common solutions to programming problems
are called design patterns Design patterns are characterized as:
Structural patterns that depict the bigger picture of how classes (things) fit together
Adapter, MVC Creational patterns depict how objects are created
Factory pattern Behavioral patterns describe the interaction
between objects
![Page 3: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/3.jpg)
Slide 3
MVC (Introduction) Design pattern with a clear separation
between application logic and the user interface
In Android, all objects fall into either a model view controller
![Page 4: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/4.jpg)
Slide 4
MVC (Model - 1) The model manages the information
and notifies the observers when the information changes
It represents the data on which the application operates
The model provides the persistent storage of data, which is manipulated by the controller In this chapter, we are modeling a true /
false question
![Page 5: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/5.jpg)
Slide 5
MVC (Model - 2) Model has no knowledge of the user
interface That’s the responsibility of the view
In Android, these are custom classes that you typically create
![Page 6: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/6.jpg)
Slide 6
MVC (View) The view displays the data It takes input from user It renders the model data into a form
(screen) to display to the user There can be several views associated
with a single model Usually for different devices
If it’s visible to the user, it’s a view
![Page 7: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/7.jpg)
Slide 7
MVC (View) The view knows how to draw itself on
the screen Together, all of the different view
objects make up the view layer Rendering a view is often called
inflating a view
![Page 8: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/8.jpg)
Slide 8
MVC (Controller 1) The controller handles all requests
coming from the view or (user interface) The data flow to whole application is
managed by the controller It forwards the request to the
appropriate handler Only the controller is responsible for
accessing the model and rendering it into various UIs (views)
![Page 9: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/9.jpg)
Slide 9
MVC (Controller 2) The controller ties the model and views
together Controllers are designed to respond to
various events triggered by view objects and to manage the flow of data to and from model objects and the view layer
![Page 10: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/10.jpg)
Slide 10
MVC (Illustration)
![Page 11: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/11.jpg)
Slide 11
Chapter 2 MVC Implementation
![Page 12: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/12.jpg)
Slide 12
MVC Benefits Separates the business logic from the
user interface We can have multiple views for different
devices Applications tend to be more structured
thereby making them easier to understand
Code reusability tends to increase
![Page 13: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/13.jpg)
Slide 13
Adding a Java Class (1) The project in the first chapter had a
single class In this chapter, you will add a second
class that will implement the model
![Page 14: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/14.jpg)
Slide 14
Adding a Java Class (2) Click File, New,
Class to create a new class Give the class
a name
![Page 15: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/15.jpg)
Slide 15
Adding a Java Class (3)
![Page 16: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/16.jpg)
Slide 16
Accessors and Mutators In C# we create what are called
property procedures to implement properties Remember that properties store data
about an object In Java, we create method pairs called
accessors and mutators Accessers read a property Mutators update a property
![Page 17: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/17.jpg)
Slide 17
Accessors Both store data in a hidden variable Accessors typically begin with the prefix
get Boolean accessors typically begin with the
prefix is Typically the value is stored in a hidden
variable
![Page 18: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/18.jpg)
Slide 18
Mutators Both store data in a hidden variable Mutators typically begin with the prefix
“set”
![Page 19: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/19.jpg)
Slide 19
Example The following contain accessors and
mutators
![Page 20: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/20.jpg)
Slide 20
Icons (Introduction) Icons are stored as external files Multiple versions of an icon are typically
needed to support different resolutions Medium (mdpi) (about 160 dpi) High (hdpi) (about 240 dpi) Extra-high (xhdpi) (about 320 dpi) Low density devices are considered
obsolete
![Page 21: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/21.jpg)
Slide 21
Icons (Implementation) Icons are stored in the res folder By convention, there are subdirectories
that store icons of the various resolutions Android figures out which icon (resource)
to use based on the device resolution png, jpg, gif formats are supported
among others
![Page 22: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/22.jpg)
Slide 22
Icons (Illustration)
![Page 23: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/23.jpg)
Slide 23
Reading Resources in XML The syntax to read a resource is similar
to the process to read a string A reference to a string resource begins
with @string A reference to a drawable resource begins
with @drawable
![Page 24: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are](https://reader036.vdocument.in/reader036/viewer/2022062500/5697bfd81a28abf838caf2f6/html5/thumbnails/24.jpg)
Slide 24
Reading a Resource (Example) Read and display the resource named
arrow_right