简体   繁体   English

将类图分成UML包

[英]Separating class diagram into packages in UML

I'm mapping out a piece of software using a class diagram, that I now want to separate into packages in a package diagram. 我正在使用类图绘制一个软件,现在我想将其分解成一个包图。

My problem is this: How do you represent connections between classes from two different packages? 我的问题是:如何表示两个不同包中的类之间的连接?

For example, I have a class in my 'Database' package that connects to another class in my 'View' package. 例如,我的“数据库”包中有一个类,该类连接到“视图”包中的另一个类。 However if I separate them into two separate class diagrams (one for each package), that connection won't be represented. 但是,如果我将它们分为两个单独的类图(每个包一个),则不会表示该连接。 Is this okay? 这个可以吗?

Packages are just one way to group UML elements and they do primarily not imply relations between the elements themselves. 包只是对UML元素进行分组的一种方法,并且它们主要并不意味着元素本身之间的关系。 To show relations between elements just connect them as appropriate irrelevant of where they are placed in packages. 要显示元素之间的关系,只需将它们适当地连接起来,而与它们在包装中的放置位置无关。 Of course, there should be more relations of elements inside a package than to those outside. 当然,包中元素的关系应该比外部元素更多。 Elements in a package indicate that they have a stronger relationship to each other than to elements outside. 包中的元素表示彼此之间的关系比与外部元素之间的关系更强。

You can show a package hierarchy on top to on package level. 您可以在软件包级别的顶部到顶部显示软件包层次结构。

When you create diagrams inside the package you can create different kinds: purely package internal, such with relations outside or a mix. 在包内部创建图时,可以创建不同的种类:纯粹是内部包,例如外部关系或混合关系。 This depends on what ever suits best. 这取决于最适合的方法。

One good use of packages is in a domain chart that shows dependencies between different problem spaces. 包的一种很好用法是在域图中显示了不同问题空间之间的依赖关系。 Each problem space is represented by a package. 每个问题空间都由一个包表示。 The packages are connected by dependency lines. 这些包通过依赖关系线连接。 This implies that each package exposes an interface to the packages that are related through the dependencies. 这意味着每个包都公开了通过依赖关系相关的包的接口。

It sounds to me like you have a bit of domain pollution. 在我看来,您有点域污染。 Perhaps the database shouldn't know about the view. 也许数据库不应该了解该视图。 Perhaps there should be a controller that reads the database and updates the view. 也许应该有一个控制器可以读取数据库并更新视图。 The class that accesses functionality within the package would access a package interface. 访问包内功能的类将访问包接口。

The benefit of this technique for system design is that this encapsulation and decoupling makes it easier to change the internals in one class without the change rippling through the system. 这种技术对系统设计的好处在于,这种封装和去耦使得更容易在一类中更改内部结构,而不会引起整个系统的变化。

It's absolutely fine to present elements from various packages on one diagram. 在一张图上显示来自各种程序包的元素是绝对好的。 In such case you should remember that package creates a namespace and thus elements should be presented with a qualified name. 在这种情况下,您应该记住,程序包会创建一个名称空间,因此应该使用限定名称来表示元素。 Note if you create a class diagram for elements from package A you need to use qualified names only for elements from other packages (eg package B). 请注意,如果为包A中的元素创建类图,则只需要对其他包(例如,包B)中的元素使用合格名称。

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

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