Creating an Observable model
To get things started on this part of the project, you'll need a new model class to encapsulate the allowance and spending of the user. We'll call the new class Allowance, and build in some utility methods to fetch useful information (such as how much the user spent between two dates). Most importantly, this new model needs to tell us when it changes. This can technically be done in several ways: through an event-bus, or specialized listeners, but for this example, we'll go with an Observer pattern. To make this work, the Allowance class will extend from BaseObservable, a convenience class that is part of the data binding API. Whenever the Allowance class changes, it'll emit events notifying its observers of the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access