使用基于关联数组的 UML 建模类型 [英] Modelling types with UML based on associative arrays

查看:30
本文介绍了使用基于关联数组的 UML 建模类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有一个 PHP 子系统,它仅使用关联数组来存储某种结构化数据.因此,实际上在语言级别上没有任何机制来约束这些结构,但您希望在您的设计中使用 UML 来定义它们.

例如:

一个联系人在 PHP 中看起来像这样一个关联数组:

<预><代码>['名称' =>'约翰·多伊','出生' =>'2000-04-01','电子邮件' =>'john.doe@company.com','地址' =>['街道' =>'123 大街','城市' =>'任何镇','状态' =>'纽约','zip' =>'1234','国家' =>'我们']]

所以我认为 UML 中的图表可能如下所示:

但有人可能会批评这是错误的,因为它显示了两个类而不是两个关联数组.所以我们可以使用(自定义)构造型来表明这不是一个常规类,而是哪个(以及如何定义它们)?

或者更常见的问题:使用 UML 定义此类数据类型的正确方法是什么?

解决方案

简单来说:你的设计是正确的.您可以"做的是使 Address 成为 Contact 的嵌入类:

如果你愿意,你可以证明它应该被实现为关联数组:

Let's say there is an PHP subsystem which uses only associative arrays to store some kind of structured data. So in fact there is no mechanism on language level to constraint those structures but you want to define them in your design with the UML.

E.g.:

A contact could look like this as an associative array in PHP:

[
  'name' => 'John Doe',
  'birth' => '2000-04-01',
  'email' => 'john.doe@company.com',
  'address' => [
    'street' => '123 Main St',
    'city' => 'Anytown',
    'state' => 'NY',
    'zip' => '1234',
    'country' => 'US'
  ]
]

So I thought an diagram in UML could look like this:

But someone might criticize that this is wrong because it shows two classes and not two associative arrays. So we could use a (custom) stereotype to to show this is not a regular class but which (and how to define them)?

Or to question in more common: What would be the/a right way to define types of such data with the UML?

解决方案

Simply speaking: your design is correct. What you "could" do is to make Address an embedded class of Contact:

And if you wish so, you could show that it shall be implemented as associative array:

这篇关于使用基于关联数组的 UML 建模类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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