Search code examples
umlrelationshipcircular-dependencyclass-diagram

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:

  • A document belongs to a DocumentType( invoice , order form , ..)
  • a documentField ( date , address , nameClient , ... ) belongs to a documentType ( each documentType has its proper fields
  • the FieldValue is the value of documentfield that will be saved in database it belongs to both document and documentField , the value should be saved according to the fieldType ( date , char , long , double... )

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.


Solution

  • 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