The Application Domain Model

When you are building an application, you will typically have some set of data that you want to interact with. You need to organize that data somehow, and you do that by creating a domain model. The domain model is a representation of the data that is relevant to your application.

This first structure is the human-understood model of the data. You will also need to map this model to the application. In Java, you can model data as classes to create the application domain model, often referred to as entities. Sometimes the original domain model matches the application domain model, but sometimes it has to be adjusted.

Domain Components in Java

Domain classes can represent generic or specific entities. Depending on the application, you could model a Person class that represents employees, customers, dependents, or even stakeholders. You could also create individual Employee, Customer, Dependent, and Stakeholder classes, and even create the generic Person class that each subclass is related to. The choice depends on the application and the domain.

Entity classes contain metadata that describe them. For example, a Person entity might have a name, dateOfBirth, address, emailAddress, and phoneNumber. These fields are often referred to as properties or fields.

Data classes can also be related to each other in various ways, depending on the business needs. You can have relationships among different data classes or between the same data class. Here are some examples.

  1. A Person entity might have a relationship to a Company entity (e.g. as an employee). This represents a relationship between two different data classes.

  2. A Person entity might have a relationship to another Person entity as a colleague or a dependent. This represents a relationship between the same data class.

  3. A Person entity might have a relationship to a Company entity, which has a relationship to a Country entity, which has a relationship to a Continent entity. This creates a path of connected entities.

Object-Oriented Programming

Java is considered an object-oriented programming language because its focus is on data objects and creating/manipulating them. Data objects are also the primary way that an application interacts with a data store. A domain can be modeled into a variety of data structures in Java, and Spring follows these conventions.

You will see how Neo4j is the perfect companion to Java and Spring due to the way it stores data as a graph of nodes and relationships.

Check Your Understanding

Application Domain Model

True or False: Sometimes the domain model and application domain model are not the same.

  • ✓ True

  • ❏ False

Hint

Each model has their own rules and limitations that may not always allow data to be structured in the same way.

Solution

Sometimes the domain model and application model are not the same. Each must meet criteria for human understanding and language constructs (in our case, Java and Spring). While the models often match, they may not in every case.

Lesson Summary

In this lesson, you learned about the domain model and application model and how they may not always match.

In the next module, you will learn about mapping the graph data model to the application domain model.