Article Preview
Buy Now
FEATURE
A Model For Health
Designing and implementing a custom data model
Issue: 16.1 (January/February 2018)
Author: JC Cruz
Author Bio: JC is a freelance writer based in British Columbia. He is a regular contributor to MacTech Magazine and Dr Dobb's Journal. Away from the writing pile, JC spends quality time with his nephew, as a proper uncle should.
Article Description: No description available.
Article Length (in bytes): 61,366
Starting Page Number: 58
Article Number: 16105
Resource File(s):
project16105.zip Updated: 2018-01-01 22:32:38
Related Link(s): None
Excerpt of article text...
In my demo project, FooHealth, I used the
SQLiteDatabase
class as my data model. And I have a module serve as controller between the model and the many entry and table views. But this approach is fraught with problems.So, today I shall demonstrate how I create a valid data model. I shall explain how I design the model class and how I re-factor the database routines. And I shall show how I modify a library module to use the data model.
Readers need a working knowledge of Xojo and object-oriented design. The updated version of the demo project FooHealth (Mk11) is available from the magazine's website.
Decoupling the Model
Using a module as controller has several problems. Consider the controller module
vitalsLib
(Figure 1). Here I have two twoSQLiteDatabase
properties:vitalsDB
andvitalsLUT
. ThevitalsDB
property manages the data table inside the SQLite fileFooHealth.dat
, whilevitalsLUT
property manages the look-up table inside fileLUTVitaMeds.dat
.Now these two tables have their own schema. But the workflow routines for both tables are quite similar. Consider the two routines in Listing 1. Both routines add a new data entry to their respective table. The method
entry_make()
hasvitalsDB
as its model, the methodlookup_make()
hasvitalsLUT
. Both also have different arguments.
...End of Excerpt. Please purchase the magazine to read the full article.