ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming...

24
ANDROID AND MODEL / VIEW / CONTROLLER

Transcript of ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming...

Page 1: ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

Slide 24

Reading a Resource (Example) Read and display the resource named

arrow_right