6. MVVM – the NeXt Generation
Model
View
View-Model
Data Binding
Service Structure
7. MVC, N-Tier, MVVM – who
cares?
Moving towards OOP
Clean division of work between functional
units
Example: Calculator Converter: Model? View?
Controller?
Project 2 – later tonight…
8. Intro to Arrays
What is an array?
A collection of related data
Similar to a set of mailboxes at a site
The site is the array, each mailbox represents an
element
The mailbox may contain a specific value or object
The contents can be strings, integers, or even
another array
Addressed using brackets or parentheses (zero-
based)
Can be examined iteratively or uniquely
9. Arrays Illustrated
Single Dimension
Array=days_of_week(7)
2-Dimensional (table)
Array=address_book(4,7)
Mon Tues Wed Thurs Fri Sat Sun
fname lname addr city prov post Email
joe smith 123 My Street Halifax NS B1B 1B1 joe@test.com
jane jones 1 Main Dr Dartmouth NS B7B 7B7 jane@mymail.com
pat white 21 Goode Dr. Halifax NS B1A 2C3 pat@hotmail.com
sam davis 19 Smith Dr. Timberlea NS B9G 2K8 sam@mailstop.com
10. Creating and Accessing Arrays
Single Dimension
a = Array.new # an empty array
a = [] # same as above
puts a => nil (no output)
a[0]=“hello” # assigns the value
a[1]=“ world”
puts a[0] + a[1]
puts a
x = [1,”green”,”martian”]
15. Iterating Through Arrays
Using each
rows=5
cols=5
countr=0
mtrx=Array.new(rows) {Array.new(cols)}
mtrx.each do |myvar|
myvar.each do |ovar|
ovar=countr
countr=countr+1
end
end
16. Iterating Through Arrays
Using for
rows=5
cols=5
countr=0
for x in (0..rows-1)
for y in (0..cols-1)
mtrx[x][y]=countr
countr=countr+1
end
end
17. Creating and Accessing Arrays
Practice
Handout: Exercise 10-2, Creating and
Accessing a multi-dimensional
Array
18. Assignment 7: Daily Agenda
Use a 2D Array to hold details
Prompt for time (hour only)
Prompt for appointment
Prompt for location
Assign inputs to elements
Continue to prompt until user types in a blank
in the time slot
Sort the Agenda and then generate Daily
Agenda by iterating through the array
19. Project 2: Battleship
Simple Version
8 x 8 grid (A-H, 1-8)
2 ships each player
Each ship assigned to a particular grid location
10 shots each player
A shot to the location of a vessel sinks it
Draw grid and results after each shot
“~” is unknown, “!” is sunk, “0” is a miss
If two of the ships of any player are sunk, the other player
wins, end game
If after ten shots one player has more ships than the other,
he/she wins, otherwise it’s a tie.
20. Wrap-up
Summary
Arrays
Analysis & Design
Assignment
Project
Next Week
Brief intro to Classes
Business Problems with Fishbone Diagram
Project Time*
21. Practice/ Set-up
Use this time to attempt the assignment to
prepare you for the project, OR
Begin to set up your tasks, OR
See me about any issues with grades, etc. OR
Do any research you need to get the
assignment or project completed.
GREAT TIP SITE:
http://www.techotopia.com/index.php/Understanding_
Editor's Notes
Model: The model contains the core information for an application. This includes the data and validation rules as well as data access and aggregation logic.
View: The view encapsulates the presentation of the application, and in ASP.NET this is typically the HTML markup.
Controller: The controller contains the control-flow logic. It interacts with the Model and Views to control the flow of information and execution of the application.