2
  • ER diagrams represent the abstract representation of the data model,
  • class diagrams represent the static structure and behavior of the proposed system.


  • Main building blocks of ER diagram are entities,
  • main building blocks of class diagram are classes,

there is a close relationship between entities in ER diagrams and classes in class diagrams
they are mapped 1 to 1 . no extra classes or no extra entities

it means

  • there is a class in class diagram for every entity in ER diagram
  • there is a entity in ER diagram for every class in class diagram

as shown below

---------------------------------------------
class diagram                    ER Diagram
---------------------------------------------
class A          <---->          Entity A
class B          <---->          Entity B
class C          <---->          Entity C
class D          <---->          Entity D
class E          <---->          Entity E

is it always there is 1 to 1 mapping between classes in class diagram and entities in ER diagram
or
is there any exceptional moment?

if there is exceptional moment when will that happens?

P.s - I am not having issue with understanding the differences between these 2 diagrams.

Susantha7
  • 898
  • 1
  • 20
  • 38

3 Answers3

1

A system developer could elect to have 1:1 representation between classes and database tables. This mapping is a choice and is not a must. It is common to use this approach in real projects. The OO world does not address the relationship types found in RDBMS naturally. For instance, you can't enforce FK in a class automatically. The decision you make is very important because many of the classes you will build will depend on it. Changing your mind at a later stage will be very costly.

The worlds of RDBMS and the OO world are 2 different worlds. In fact there are object databases that fully support OO (for example see:Wiki-Object-Databases. The differences go beyond the issue you raised. There is a group of tools that have been created to address some of these differences or at least act as a bridge between these two worlds. for some background on this concept see for example: Wiki-Object Relational Mapping.

To get more about the differences between the OO world and the relational word, you may want to check this: Wiki-Object-relational impedance mismatch.

Many other references exist on this topic for example:is-there-really-object-relational-impedance-mismatch.

It maybe good to ask when NOT to use 1:1 mapping...This would be an interesting question.

NoChance
  • 5,632
  • 4
  • 31
  • 45
  • 2
    This requires some analysis...One case for example, if you have many classes that inherit from a parent class, and the parent class has many methods, you don't want to have to code the many methods in each child class. However, it is possible that there is an OO Pattern that covers this. – NoChance Aug 09 '17 at 11:16
  • @Susantha7 One-to-one mapping can be appropriate when building simulations of a domain. It's not generally appropriate when building information systems for a domain. – reaanb Aug 10 '17 at 05:53
0

Well, you can map 1:1 but you must not. The 1:1 path is the easiest in a first quick approach. But often you want/need to introduce redundancy in tables for performance reasons. So in that case your tables do not represent what your classes tell.

What you do in such cases is to derive a database model from the more abstract class model. Many tools offer transformations to support such kind of task (though I prefer the simple copy/paste and just set a <<derived>> relation between the packages).

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
0

All depends on the purpose of your two models. If both class and ER diagrams are intended to represent a single design or single implementation of something then the obvious question is why do you need two different pictures of it? On the other hand if they are two different implementations, possibly using different technologies and doing different jobs, then that will have some bearing on how you map one onto the other. There cannot be a single answer for every situation.

You have tagged this with the relational-database tag although it isn't directly relevant to your question. In the relational model, relation schemas are variables whereas classes are types. Fundamentally those are very different things, and the error of treating them as equivalent has been called the First Great Blunder. You have not made that error in your question but you may find this link enlightening.

nvogel
  • 24,981
  • 1
  • 44
  • 82