Amirhosein Al
Amirhosein Al

Reputation: 500

UML Class - Using the base class when there are no derived classes

Hello I'm trying to prepare an ER diagram + a class diagram. The system is very simple. It involves a simple flight reservation system with two roles (actors).
In the ERD, we can distinguish between the two roles using the "IsAdmin" attribute("true" for admin, and "false" for customer).
In the class diagram, I have a base class named "User" (containing all the attributes and methods of the customer role and all the attributes and some of the methods of the admin role).
Should I use the User class when dealing with the customer entity (since the attributes and methods are the same), or should I create an empty class derived from the User class for clarity?
ERD

Class Diagram

Upvotes: 2

Views: 1124

Answers (2)

Gerd Wagner
Gerd Wagner

Reputation: 5673

ER Diagrams (ERDs) and UML Class Diagrams (CDs) are both information modeling languages that essentially cover the same concepts, but using a different visual syntax. Both allow modeling classes with properties/attributes (and operations/methods in the case of CDs) defining entity types, and associations (or relationship types).

Since CDs have been defined more recently, they are more expressive than, and subsume, ERDs. Consequently, there is no need to duplicate an information model both as an ERD and a CD. Rather, you should make a logical class design diagram from which you can obtain both OOP class models (defining, e.g., Java classes) and RDB table models.

If needed, you can derive an ERD from your CD.

Upvotes: 0

qwerty_so
qwerty_so

Reputation: 36333

It depends...

Basically when dealing with business objects I would not use a class named "User" which says all or nothing. You have a "Customer" and an "Admin" and likely many other "User"s. Don't make the "User" a "Customer".

Setting that aside, if you are using a serialization framework that often requires table and class to have the same name.

Also you shouldn't start a system with optimization. Give clarity an advantage in favor of that. It will pay out more sooner than later. And in any case: you can optimize at later stages as well.

Upvotes: 3

Related Questions