我如何避免在班级图中出现循环关系 [英] how do i avoid a circular relationship in my class diagram

查看:80
本文介绍了我如何避免在班级图中出现循环关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对我的数据库设计面临的一些循环关系有疑问。我读了一些其他类似的问题,但不能解决我的问题,所以这是我的类图:

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 :

,这是逻辑:


  • A document 属于 DocumentType (发票,订单,..)

  • a documentField (日期,address,nameClient,...)属于documentType(每个documentType都有其适当的字段

  • FieldValue是将保存在数据库中的documentfield的值,它既属于document又属于documentField,该值应根据fieldType保存(date,char,long,double ...)

  • 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.

在此先感谢您的帮助。

推荐答案

在这里,这种情况甚至比其他类似情况更简单。题。显然,最下面的两个类描述了抽象的文档结构,而最上面的两个类描述了具体的文档

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:


  • Document和FieldValue之间的关联应为构成

  • 一些较低的多重性应更改为0(而不是1),以使您的模型实例化更加灵活(例如-为什么不允许没有DocumentFields的Document?很明显,您迟早会添加一些字段,但是您可能可以先创建一个空Document并保存它)

更新:

这篇关于我如何避免在班级图中出现循环关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆