Skip to content

Modelable Concepts

Adrian Testa-Avila edited this page Aug 5, 2017 · 2 revisions

The whole idea of modelables is not only built around the data that a domain model contains, but also how we interact with that data. Understanding these driving concepts can help with making your own modelables.

Note that none of these concepts are exclusive. Any given property might be readable, writable, enumerable, and/or identifiable, as appropriate for the specific modelable.

  • readable properties are those which, well, can be accessed (read!) by outside code.

  • writable properties are those which can be modified by outside code.

    Validation is part of writing. There are several ways that validation might be implemented in modelables, but the important thing to note is that if outside code successfully sets a value, it can be assumed that that value is valid.

  • enumerable properties are those that are exposed when iterating oven the modelable.

    The Modelable interface extends the ArrayAccess, Iterator, and Jsonable interfaces, and those methods must all work with the same set of properties. For example, iterator_to_array($modelable) returns, by definition, the same property→value collection that $modelable->toArray() does. Obviously, enumerable properties are all readable, but not all readable properties must be enumerable.

  • identifiable properties are those which uniquely identify the modelable.

    Some modelables, such as pure value objects, might include all properties in this definition (i.e., instances with the same values are considered to be the same); others might have no identifiable properties at all (i.e., every instance would be considered unique, even if they had all the same values).

    Identifiable properties can be thought of in RDBMS terms as "primary keys." Note, however, that the database is not their primary (no pun intended) purpose. In particular, there is a tendency to make a database table's primary key a serial integer — identifiable properties should be "natural."


The characteristics above deal with high-level concepts — they group properties by their purpose, and how they are interacted with by outside code. Being an interface, Modelable isn't tied to any specific implementation, but there is another concept with will guide the implementation: literal and virtual properties.

  • literal properties are those actually defined on the modelable class. These values are everything the modelable "needs to know." In RDBMS terms, the literal properties is the modelable's "normalized" data.

    The Modelable interface extends the Serializable interface, and it's literal properties that are serialized or persisted in storage.

  • virtual properties are inferred, or calculated, from one or more literal properties. They are used to expose useful "views" on the modelable's data.

Clone this wiki locally