KIEI-451: Introduction to Software Development

Domain Modeling

How To: Start Domain Modeling

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.

Models and Their Attributes

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.

Database-Backed Models

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.

Naming Conventions

While there exist several plausible approaches to model and attribute representation, we will adopt conventions set forth by many web development frameworks today:

  1. Collection/table names will be lower-case and preferably one word, i.e. products, books, 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: productCategories, buildingMaterials. This matches conventions for JavaScript variable naming.
  2. Collection/table names must be pluralized nouns.
  3. Attribute names are lower camel-case only: title, firstName, city.
  4. Every collection/table must have an attribute for its document ID, that is, an attribute that uniquely identifies each record. This is typically auto-assigned by the database software.
  5. Every attribute must have a specified data type: number, string, timestamp, or boolean.
  6. Attributes can hold a single atomic value only, not a list of values.
  7. Attributes which are intended to store the identifier of a row from a different table are called foreign keys and use the Id suffix, e.g.: directorId, productId, movieId.

Attribute Types You Can Use

Type Description Notes
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

Example: Collections for imdb.com (initial version)

movies
id
(auto-generated)
title
(string)
directorId
(string)
year
(number)
synopsis
(string)
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")
directors
id
(auto-generated)
name
(string)
photoUrl
(string)
e59f19af1d4f5b11b771 Ron Howard http://ia.media-imdb.com/images/M/MV5BMTkzMDczMjUxNF5BMl5BanBnXkFtZTcwODY1Njk5Mg@@._V1_SX214_CR0,0,214,317_.jpg
25efdd6a55ae58eb258d Steven Spielberg http://ia.media-imdb.com/images/M/MV5BMTY1NjAzNzE1MV5BMl5BanBnXkFtZTYwNTk0ODc0._V1_SX214_CR0,0,214,317_.jpg