marcAntoine
marcAntoine

Reputation: 678

how do i avoid a circular relationship in my class diagram

Hi I have a question about some circular relationships that I am facing with my database design . I read a few more similar questions but couldn't solve my problem, so here is my class diagram : enter image description here

and here is the logic:

However, from a database architect perspective, this circular relation is incorrect since it can results in integrity problems:

Should you have any idea how to deal with this, please be welcomed to comment.

Thank you in advance for your help.

Upvotes: 3

Views: 2875

Answers (2)

Aleks
Aleks

Reputation: 5864

Here the situation is even simpler than in your other similar question. It is clear that bottom two classes describe the abstract document structure, while the top two classes describe concrete documents.

Abstract elements should never depend on concrete ones, so just make two vertical associations unidirectional and point them towards abstract classes. This will break the circular dependency neatly.

In addition, I would further refine your model:

  • The association between Document and FieldValue should be a conposition.
  • Some lower multiplicities should be changed to 0 (instead of 1), to make your model instantiation more flexible (for example - why not permit a Document with no DocumentFields? It is clear that you will sooner or later add some fields, but you can probably create an empty Document first and save it)

UPDATE:

enter image description here

Upvotes: 1

Andrea Sindico
Andrea Sindico

Reputation: 7440

I can't actually see the aim of your modeling. It seems to me you are mixing meta-elements ( DocumentType and DocumentField) with modeling elements instances of the meta-elements (Document and FieldValue).

What is the semantics of the Document-->DocumentType relationship ? is it an "isA" relationship? if so why don't you use extension/generalization (inheritance) or interface realization (implementation)?

Why do you need the inverse relationship DocumentType-->Document? if You could avoid it you wouldn't have the circular relationship.

[Update] Why don't you rename DocumentType in AbstractDocument and make it an abstract class. Then replace the association from Document to DocumentType with an extension (generalization) Finally create a 1..* association from AbstractDocument to itself

[Update2] Also consider that according to your explanation the association from Document to DocumentType has different sematnics and thus is different (another association) from the association that goes from DocumentType to Document

Upvotes: 0

Related Questions