Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 14 in printed book and digital formats -- plus a one-year subscription so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Recent issues

Article Preview


Buy Now

Issue 16.1 ('London 2017')
Instant purchase and download via GumRoad!

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):

Download Icon 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 two SQLiteDatabase properties: vitalsDB and vitalsLUT. The vitalsDB property manages the data table inside the SQLite file FooHealth.dat, while vitalsLUT property manages the look-up table inside file LUTVitaMeds.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() has vitalsDB as its model, the method lookup_make() has vitalsLUT. Both also have different arguments.

...End of Excerpt. Please purchase the magazine to read the full article.