Model

Summary

The abstract base class for models.

Description

The Model abstract class is the abstract base class for models in Altitude MVC/MVP applications.

In Altitude, business logic should be contained in the models.

Examples

Basic Usage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import System;
import Altitude.Frontend;
 
// Create the model
class Temperature : Model
{
    Date date;
    double degrees;
 
    Temperature(Date date, double degrees) {
        this.date = date;
        this.degrees = degrees;
    }
 
    void setDegrees(double degrees) {
        this.degrees = degrees;
    }
}
// Create multiple views
class BarChart : View
{
    // ...
}
class LineChart : View
{
    // ...
}
 
// Instantiate models
Temperature temp1 = new Temperature(new Date(), 27);
Temperature temp2 = new Temperature(new Date(), 30);
 
// Instantiate views
BarChart barChart = new BarChart();
LineChart lineChart = new LineChart();
 
// Attach views to models
temp1.attach(barChart);
temp1.attach(lineChart);
temp2.attach(barChart);
temp2.attach(lineChart);
 
// Initialize views (perform initial render) to the data in `temp1`.
// (Assuming data for `temp2` is initially hidden until the user, via
// the user interface, enables it.)
barChart.initialize(temp1);
lineChart.initialize(temp1);
 
// Change the data from the initial render
temp1.setDegrees(37);
temp2.setDegrees(40);
 
// Update all views
temp1.updateAll();
temp2.updateAll();
 
// Detach a view
temp1.detach(lineChart);
 
// Update again...
temp1.updateAll(); // Now only the bar chart gets updated for `temp1`'s data

Methods

  • attach

    Attaches a view to the model.

  • detach

    Detaches a view from the model.

  • toExternal

    Converts the model data to an external JavaScript format for view rendering.

  • updateAll

    Updates all attached views.

  • updateOnly

    Broadcasts the specified changeset to all attached views.

Share

HTML | BBCode | Direct Link