Reputation: 105
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?
Upvotes: 2
Views: 6336
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
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:
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.
Upvotes: 2
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
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:
«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