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 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061import System;import Altitude.Frontend; // Create the modelclass 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 viewsclass BarChart : View{ // ...}class LineChart : View{ // ...} // Instantiate modelsTemperature temp1 = new Temperature(new Date(), 27);Temperature temp2 = new Temperature(new Date(), 30); // Instantiate viewsBarChart barChart = new BarChart();LineChart lineChart = new LineChart(); // Attach views to modelstemp1.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 rendertemp1.setDegrees(37);temp2.setDegrees(40); // Update all viewstemp1.updateAll();temp2.updateAll(); // Detach a viewtemp1.detach(lineChart); // Update again...temp1.updateAll(); // Now only the bar chart gets updated for `temp1`'s data Methods attachAttaches a view to the model. detachDetaches a view from the model. toExternalConverts the model data to an external JavaScript format for view rendering. updateAllUpdates all attached views. updateOnlyBroadcasts the specified changeset to all attached views. Share HTML | BBCode | Direct Link