Hols_79
Hols_79

Reputation: 13

The components of a Class Diagram and how it differs to ERD

I want to understand a class diagram more fully and I am finding lots of conflicting information.

My first question is, what is the difference between class diagram and ERD? Not necessarily in look, but in classification. e.g. I have read that a class diagram is a type of ERD and I have read that a class diagram and an ERD are two different things.


My second question is around how the class diagram should look, I was given a basic tutorial on how to create a class diagram and I was taught that each class should be connected with a single line, with an arrow that looks like a 'Play' symbol (example 1 in the attached image)

But since doing some research into it, I am finding lots of examples where different connectors are used to denote association, aggregation, composition, inheritance etc. (example 2 in the attached image)

As mine is more simplistic, just showing the relationship and the multiplicities, does that mean that I have just learned a more basic version of class diagram and the extra connectors are an advanced step? Or are they both something different?

class diagram examples

Thanks for your help

Holly

Upvotes: 1

Views: 995

Answers (1)

mirind4
mirind4

Reputation: 1563

First of all, welcome to Stack Overflow!

A class diagram is a type of static structure diagram that describes the structure of a system by showing the system's classes, their attributes, operations (or methods), and the relationships among objects. Wiki link

An entity relationship diagram (ERD) shows the relationships of entity sets stored in a database. Link

Therefore the answer to your question of "what is the difference between class diagram and ERD"?

The class diagram has nothing to do with fact how the classes are persisted in the data layer. It shows only the logical relationship between classes and the properties of the classes. While the ERD diagram illustrates the logical structure of database; what the database tables, table-column, primary keys, foreign keys, etc. are, and last but not least the relationships between database tables.

As for the question "Is this just a more advanced version of class diagram? Or a more updated version?":

There are cases when the ERD diagram can look similar to the corresponding class diagram, but the persistence data model can be way different from the class (domain) model. Furthermore a class diagram has no any information about how a class is persisted in the database - as I've already mentioned -, therefore an ERD has other kind of information than a class diagram.

As for the notations you linked: A proper class diagram contains notations like in the second link. An example is the following diagram: Class diagram

For more info what those arrows mean, click here for the corresponding SO answer.

What you are taught about how to make a class diagram (like at the first link you shown), can also be useful but it is a customized class diagram rather than an proper class diagram following the UML standards and notations because:

  • I find it strange that the arrow is not on the line itself
  • There is a shared ownership relationship (aggregation) between Customer and Vehicle. It means that a Customer can have (own) a Vehicle but the Vehicle can still exist as its own, without a Customer. This relationship can be represented with the aggregation notation. (See arrow 5a, or the class diagram below)
  • I find it also strange that a vehicle can have multiple Customers, as you notated with "0..*". But of course it is possible, since I do not know what kind of domain you try to model with the diagram...I made an UML diagram with proper signs, check this out:

Propert UML class diagram

Summing up, it is wise to follow the UML standards and conventions, since it is widely accepted and known so the information can be exchanged as efficient as possible, without misunderstanding.

Upvotes: 1

Related Questions