简体   繁体   English

ERD图转换成UML图

[英]ERD diagram conversion into UML diagram

I have an ERD Diagram of an E-commerce with the following entities Product , Tag , ProductTag , Category and other entities of course.我有一个电子商务的 ERD 图,其中包含以下实体ProductTagProductTagCategory和其他实体。

在此处输入图像描述

I tried to convert it into class diagram as follows:我试着把它转换成class图如下:

1- removed the id

2- converted the foreign key into object of the type i'm refering to(product_id converted into => product: Product)

my question is, is this good approach to follow on all my entities?我的问题是,这是跟踪我所有实体的好方法吗? does it like achieve the SOLID principle?它喜欢实现 SOLID 原则吗? I have a presentation in 2 days and I want to be very sure of what I have made, any comment or modification would be really enough.I also chose these tables because they represent one to many and many to many.我在 2 天内有一个演示文稿,我想非常确定我做了什么,任何评论或修改就足够了。我还选择了这些表,因为它们代表一对多和多对多。 thanks in advance.提前致谢。

在此处输入图像描述

Basically your approach is correct.基本上你的做法是正确的。 It's just a couple of UML specifications you got wrong.这只是您弄错的几个 UML 规范。

  1. The label in the middle of the connectors is just the name of the connector.连接器中间的 label 只是连接器的名称。 Unless you do some OCL wizardry this name is meaningless.除非你做一些 OCL 魔法,否则这个名字是没有意义的。 There is a way to adorn it with a black triangle to show the reading direction.有一种方法可以用黑色三角形装饰它来指示阅读方向。 This sometimes helps business people to understand how classes are related to each other (see Fig. 11.27 on p. 202 of UML 2.5).这有时可以帮助业务人员理解类之间的关系(参见 UML 2.5 第 202 页的图 11.27)。 But usually you would not use it.但通常你不会使用它。

  2. The shared aggregation has no semantics (p. 110 of UML: Indicates that the Property has shared aggregation semantics. Precise semantics of shared aggregation varies by application area and modeler. ).共享聚合没有语义(UML 第 110 页:表示属性具有共享聚合语义。共享聚合的精确语义因应用程序领域和建模者而异。 )。 So leave the open diamond away.所以离开空心钻石。 Composite (filled diamond) can be used to show responsibility (when I'm killed I will kill my composites first). Composite(实心菱形)可以用来表示责任(当我被杀死时,我会先杀死我的复合材料)。 Usually it adds too little to be really useful, it only heats up the futile composition-discussion.通常它添加的太少而不能真正有用,它只会使无用的组合讨论升温。

  3. The navigation-direction is incorrect.导航方向不正确。 The AC in the middle sees both connected classes so it's shown without any arrow.中间的 AC 可以看到两个连接的类,因此显示时没有任何箭头。 If you have an additional (directed) association you place it as lone (extra) connector.如果您有一个额外的(定向的)关联,您可以将其放置为单独的(额外的)连接器。 In that case put role names towards any end.在那种情况下,将角色名称放在任何一端。 That makes navigation clearer than just a simple arrow.这使得导航比简单的箭头更清晰。 I for myself use arrows only on rough sketches on the drawing board.我自己只在绘图板上的粗略草图上使用箭头。

PS Just noticing that you have operations in your classes that have the same name as the class and take one paramter being also the class. I would guess you intend to show a constructor here. PS 只是注意到您的类中有与 class 同名的操作,并且采用一个参数也是 class。我猜您打算在这里显示一个构造函数。 In that case you would make it Classname():Classname and provide only the paramaters that are needed for the constructor.在那种情况下,您可以将其Classname():Classname并仅提供构造函数所需的参数。 Else these opreations don't seem to make much sense.否则这些操作似乎没有多大意义。 Similarly the CRUD operations seem to work on a list of 'itself' which is also probably not desired.类似地,CRUD 操作似乎在“自身”列表上工作,这也可能是不需要的。 You would have a collection class which handles the base class where these operation make sense.您将拥有一个集合 class,它处理这些操作有意义的基数 class。 So to summarize: you would only add getter/setter operations for the (private) properties matching the columns from your table.总结一下:您只会为与表中的列匹配的(私有)属性添加 getter/setter 操作。

PPS: As per Christophe's comment it's a good idea to adorn the class instantiation operation with a <<create>> stereotype which highlights its purpose. PPS:根据Christophe 的评论,用<<create>>原型装饰 class 实例化操作是个好主意,它突出了它的目的。 See p.见第196 of UML 2.5: UML 2.5 的 196: 在此处输入图像描述 This stereotype is part of the standard (see p. 677) and the table on p.这种刻板印象是标准的一部分(参见第 677 页)和第 677 页的表格。 678 states: 678 条规定:

Specifies that the designated feature creates an instance of the classifier to which the feature is attached.指定指定的特征创建该特征所附加到的分类器的实例。

On the modeling part of your question, there's already a perfect answer .在你问题的建模部分,已经有一个完美的答案 For the records, I'd nevertheless like to add a complementary answer on the SOLID part:作为记录,我还是想在 SOLID 部分添加一个补充答案:

  • S ingle responsibility: your classes have more than one reason to change, because you may want to change Product for what it is (eg add more product-related attributes), but you may also want to change the class to add new getByXxx() operations to find products in the database based on other criteria, independently of what a product really is.单一责任:你的类有不止一个改变的理由,因为你可能想改变Product的本来面目(例如添加更多与产品相关的属性),但你可能还想改变class以添加新的getByXxx()根据其他标准在数据库中查找产品的操作,与产品的真实情况无关。 SO it's not complying.所以它不符合规定。

  • O pen-closed principle: we cannot tell O笔封闭原则:我们不能说

  • L iskov substitution principle: in absence of inheritance, this is not relevant. l iskov替换原则:在没有inheritance的情况下,这个是不相关的。 Moreover, you couldn't tell without having precondition, postcondition and invariant constraints.此外,如果没有前置条件、后置条件和不变约束,您将无法判断。

  • I nterface segregation principe: is probably not compliant, because you impose an implicit interface that all inheriting class would have to provide, even if they don't need it (eg products not stored in a database). I nterface segregation principe: 可能不合规,因为你强加了一个隐式接口,所有继承 class 的人都必须提供,即使他们不需要它(例如,产品不存储在数据库中)。 A first step in the right direction, would be to use an interface for the common database operations.朝着正确方向迈出的第一步是为通用数据库操作使用一个接口。

  • D ependency inversion: we cannot tell but probably it isn't, because update(), delete(),... probably depends on some database, so that you can't switch it to another database.依赖倒置:我们无法判断,但可能不是,因为 update()、delete()... 可能依赖于某些数据库,因此您无法将其切换到另一个数据库。 With DIP, you'd inject the database in the class that use it, so that you could at any moment inject another database that offers the same interface.使用 DIP,您可以注入使用它的 class 中的数据库,这样您就可以随时注入另一个提供相同接口的数据库。

You didn't ask, but your design seems to correspond to active records .你没有问,但你的设计似乎对应于active records If you want to go for a cleaner, more SOLID design, you should prefer factor out the database related code to either repositories or table data gateways .如果您想 go 获得更清晰、更 SOLID 的设计,您应该更喜欢将数据库相关代码分解为存储库表数据网关

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM