When we build an app, we represent real-world entities inside the virtualized world of our software. Our job as software developers is to represent those real-world things as best we can. How do we begin? We first identify all of those entities which comprise our particular domain of concern, as well as the interconnections that exist between them.
Identifying all of the real-world things that our software must contain is harder than it sounds. But here's the good news. We do not have to figure out our entire domain model up front. Instead, we start by identifying only those entities that are most central and most obvious to our application. Identifying the first few models is more than enough to begin the initial version of our app.
From now on, we will call each real-world entity a model.
And all of our models, together with all of their relationships, is called our domain model.
Most models have data associated with them.
For example, suppose we identify a User as one of our models. Users do not exist in theory. Users exist in our real world. They are the actual people that use our software.
So our next step is to figure out what data we need to keep track of when we think of our users. We will probably need to track:
The data set pertaining to a given model is called the model's attributes.
Here's another example. Suppose we're building an online newspaper. Can you name at least one model that we will need?
How about articles? Ok, what data would we need to keep track of an article?
Hopefully you're getting the idea that to start building our domain model, we identify models - real-world things that our software must emulate - and then identify the model's primary attributes.
A model and its attributes can be neatly represented in a database table (relational database) or collection (NoSQL database). If you're familiar with an Excel spreadsheet, then you already know what a database table/collection is: a set of rows and columns.
Each model will need a different table/collection, because the column definitions will be different for every model.
While there exist several plausible approaches to model and attribute representation, we will adopt conventions set forth by many web development frameworks today:
movies. Multi-word names are joined together using lower camel case, starting with lower-case, separating words with capital letters into a single word identifier:
|number||An integer or floating-point decimal||Good for prices, numbers, quantity, etc.|
|string||Text||Good for a headline, title, tweets, website URLs, articles, etc.|
|boolean||true or false||Good for checkboxes, on/off states, yes/no answers, etc.|
|timestamp||A date and time|
|51bac9ec4eaa0f6dda00||Raiders of the Lost Ark||25efdd6a55ae58eb258d||1983||I hate rats.|
|2844f5ead675ebc81dc5||Apollo 13||e59f19af1d4f5b11b771||1995||Wonderful documentary about computers, people, and error messages.|
|7bfdb14192e1bdeed614||Lincoln||25efdd6a55ae58eb258d||2012||He dies at the end. (Oops, should have said "spoiler alert")|