UML – How to Define a Class Diagram from an Entity Relationship Diagram?

uml

I'm currently working on a project in which we're required to define a Entity Relationship Diagram and a UML Class Diagram from a set system.

I've successfully managed to define the ERD. It required me to break down information from a specification and form them into entities and then define a relationship between the entities to represent the system.

Now that I've done that I'm now onto the UML Class Diagram, but the only issue is I have no idea how to incorporate what I've defined inside my ERD into a UML Class Diagram as I've been told the structure between both diagrams are quite different.

  • Do entities from the ERD in a sense serve as a class in the UML?
  • Do the attributes from the entities in the ERD form the attributes in
    the classes?
  • How can you easily define what attributes and methods you make
    public, private, and protected?

I understand a lot of the basics of UML and ERD on their own, but to take an entity relationship diagram and appropriately incorporate it into a UML is something i'm quite lost on where to start with.

Any tips or advice would be greatly appreciated.

Best Answer

UML class diagrams can be seen - roughly - as a superset of ERDs. UML class diagram notation is younger, surely made with the intention to incorporate or replace older notations like ERD, and it contains additional elements like inheritance, methods, or private attributes which are not part of ER modeling. ERDs were made strictly with data modeling for relational databases in mind, UML was designed for a broader usage, primary class modeling, but not exclusively for this.

So it is not astonishing you can take any ERD and transform it into an UML class diagram by the obvious translation "entity->class", "attribute->attribute", "relationship->relationship". The visibility of the attributes should all map to "public", since ERDs doesn't have a concept of private attributes (and obviously not of protected ones, since ERD also lacks the inheritance concept).

Googling for "translate ERD to UML" found me this scientific paper on mapping between UML and ER models, I think there you find much more about the gory details.

Another aspect here is when you want your graphical models to match exactly an implementation in code. Object-relational mappers (ORM) like MS Entity framework or Hibernate have typically specific rules how to generate classes in a programming language from a database schema. If you want your class model to match exactly the generated classes of an ORM, the best way is probably to map the ERD into a physical DB schema first, let the code generator of your favorite ORM generate classes in code, and then try some UML reverse engineering tool to create a class diagram from that code.

Related Topic