Categories: Tutorials

Type, Subtype, and Category Patterns in Logical Data Modeling

3 min read

Before I cover the three logical data modeling patterns, let’s review briefly how we typically model a type. Let’s say you’re in a car business. You can model a car as a Car entity shown in the figure below; its sample data values are in following table (I just use six numbers for the VIN, instead of the 17 characters VIN standard, in the sample). VIN (Vehicle Identification Number), the car serial number, is the unique key of the Car entity. The other attributes (Brand, Model, Year, and Manufacturer’s Suggested Retail Price) can be thought as the type of a specific car  with a unique VIN. So, the type is in the entity itself. Note that you can have more than one car—each with a unique VIN—that have the same type, such as the first three Honda Accord in the sample table. If you have many cars of the same type, or, you have many car types and they’re dynamic (have changes:  new, update, delete; for example, the update on the MSRP), you can easily recognize that this model is then not suitable—type model is a better solution.

 

VIN

Brand

Model

Year

MSRP

123987

Honda

Accord

2007

20,000

456321

Honda

Accord

2007

20,000

555666

Honda

Accord

2007

20,000

678345

Toyota

Corolla

2008

21,000

 

 

 

Type

The ER (Entity Relationship) diagram of the following figure shows Car Type and Car entities and their relationship. Car Type defines each type of your cars—a type is a definition of something. The Car is the individual car, each with a serial number (Vehicle Identifier Number) that has a specific type defined in the Car Type. You can think of a Car Type entity as a template used (instantiated) by an individual car. Now you can have as many car types as you need, and type changes don’t affect the cars. Table two tables after the figure contain sample data values of the Car Type—Car data model.

Note that a car can belong to one car type only. On the other hand, a car type can be the type of many cars.

 

Car Type Key

Brand

Model

Year

MSRP

1

Honda

Accord

2007

20,000

2

Toyota

Corolla

2008

21,000

 

 

 

VIN

Car Type Key

Owner

123987

1

Djoni Darmawikarta

456321

1

Kevin Peter

555666

1

Rao Ganipineni

678345

2

Sherman Chang

How do we deal with product that doesn’t have an individual identifier? Can we apply the same data modeling structure to, for example, commercial books? You certainly have inventory; each Inventory is an instance of the Book Type. The following figure shows the Book Type—Book data model and its sample data values, respectively.

You can also apply the same data model to intangible thing, such as Service; an individual service may be identified by, for example, a contract number. The following figure  and the last table in the article show the Service Type—Service data model and its sample data values, respectively.

Subtype

What if you have cars that have different sets of attributes, meaning different types? You can model the different types as subtypes. The following figure shows two subtypes of the Car Type entity: Passenger Car Type and Truck Type. The Car supertype has the common attributes of its subtypes while each of the subtypes has its different attributes.

Category

While Type is a definition of something, Category is a way to categorize something. While Service can be of only one type, it can be of more than one category—its relationship to Category entity is many-to-many. An example of category for Service is shown in the following figure and its sample data values in the table after it.

Note that you need to resolve the many-to-many relationship at implementation time

 

Service Category Key

Service Category

1

Bundled

2

Outsourced

3

Onsite

4

Software

5

Hardware

Summary

Type, Subtype, and Category are similar patterns for data modeling. This article introduces these three patterns and shows their differences.

One or more of them exist in most data model. If your initial data model doesn’t have any one of them then you should re-inspect the data model.

Packt

Share
Published by
Packt

Recent Posts

Top life hacks for prepping for your IT certification exam

I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…

3 years ago

Learn Transformers for Natural Language Processing with Denis Rothman

Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…

3 years ago

Learning Essential Linux Commands for Navigating the Shell Effectively

Once we learn how to deploy an Ubuntu server, how to manage users, and how…

3 years ago

Clean Coding in Python with Mariano Anaya

Key-takeaways:   Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…

3 years ago

Exploring Forms in Angular – types, benefits and differences   

While developing a web application, or setting dynamic pages and meta tags we need to deal with…

3 years ago

Gain Practical Expertise with the Latest Edition of Software Architecture with C# 9 and .NET 5

Software architecture is one of the most discussed topics in the software industry today, and…

3 years ago