Elin
Elin

Reputation: 105

Does the Class Diagram present the Database structure?

I am starting a whole project by myself for the first time, and I am stuck between the UML modelization ( Class diagram ) and the database structure.

Should I use the exact same classes that I model in the class diagram in the database?

For example, I have two User, the Service_provider and the Client. In the class diagram I consider each one of them as a unique class. But I chose to use single table inheritance in the database, so I store both users in the same table and add the role attribute to it.

Does my modelization stay valid in this case? or I just need one class for User? (but in this case, I can't show the relationship between the Service_provider and the Client as the Service_provider could have many Clients)

Could anyone explain this to me, please?

here are my thoughts for the class diagram

Upvotes: 2

Views: 6336

Answers (4)

diogoslima
diogoslima

Reputation: 189

In a nutshell (and as we discussed in the comments), your model is valid and fine :)

Of course, my answer is considering the decision was made with knowledge of both the application and the database requirements. And also understanding you have a good grasp of available options (such as the ones enumerated in this other post).

Usually, best practices guide us that a relational database and an application have independent designs, as they are built on top of different requirements. Therefore, there is no need to try perfectly matching their components, but make sure that data schema and relations are well defined.

Upvotes: 1

Gerd Wagner
Gerd Wagner

Reputation: 5673

The development of an app is supported by an entire set of (evolving) models, as illustrated in the diagram below.

The three main purposes of making UML class models when developing an app are:

  1. Describing the entity types of the app's problem domain for analyzing and better understanding the requirements for the app in a conceptual (domain) model.
  2. Designing the schema of the app's underlying database (this is typically an RDB schema defined with a bunch of CREATE TABLE statements).
  3. Designing the model classes of the data model of your app, which will be coded, e.g., as Java Entity classes or C# classes with EF annotations.

For 1 and 2, you may take a look at my book An introduction to information modeling and databases, while for 3 you may check out a book on model-based development, e.g. for Java Backend Apps or JavaScript Frontend Apps.

enter image description here

Upvotes: 2

qwerty_so
qwerty_so

Reputation: 36333

Although the existing answers already describe the problem domain I want to add that independent class design and database models (both derived from an abstract analysis model) will evolve over time. Some tools support model translation and tracebility, but I would not trust these too far. Better to have your individual traceability and good mechanisms set up to keep the models in synch. That can get tricky over time and needs thorough analysis on top of any modeling.

Upvotes: 1

Christophe
Christophe

Reputation: 73587

UML models can coexist for different purpose. For example, you could use an analysis diagram to understand the domain, a design diagram to show the conceptual solution, and an implementation diagram for the details of the real solution.

You can also keep a single model that evolves. But in this case, you'd loose the initial design to keep only the implementation model. Unfortunately this model is the least useful since it is somewhat redundant with the information in the code and is quickly obsolete.

I'd therefore strongly advise to keep both:

  1. the true design model that shows the classes as you see them;
  2. a database model with the tables to document the ORM mapping. For this you coud use a database profile for UML to add a «table» stereotype

In pure DB modelling it is also common to distinguish the logical model (entities, relationships) and the physical model (the tables implementing the logical model) for similar reasons.

Examples:

Upvotes: 3

Related Questions