This post is an extension of an earlier post entitled “Flex Part 02: Value Objects & Model Objects“.
Recap: Model Objects are similar to Value Objects in that they hold the same data, except that the Model Object is responsible for making sure that no ‘bad’ data gets into the VO. The Model Object enforces business rules like, “phone must be at least ten digits long” which a VO cannot do on its own. A Model Object may even include methods for easily manipulating properties.
In the earlier post I presented some example code for a Model Object. It turns out that what I provided is a pain to maintain over time. There’s just too much duplication and poor use of public properties. Continue reading for my attempt at a better, easier Model Object …
Continue reading ‘Flex Part 02+: A Better Model Object’
Value Objects
Value Objects are ActionSrcipt classes which are stored in the project’s vo directory.
Think of a Value Object as a row in a database table. Let’s imagine a table named
schools with columns for name, phone, address and ranking. Imagine also a related table of students.
Table: schools (one school has many students)
+------------+---------------+
| Field | Type |
+------------+---------------+
| id | Number |
| name | String |
| phone | String |
| address | String |
| ranking | Number |
+------------+---------------+
Table: students
+------------+---------------+
| Field | Type |
+------------+---------------+
| id | Number |
| school_id | Number |
| name | String |
+------------+---------------+
Each row in the schools database table will have several properties which effectively describe a single School. The properties of a School contain simple values: strings, numbers, dates etc. This is the essence of a Value Object (VO).
Continue reading ‘Flex Part 02: Value Objects & Model Objects’