Modelling types with UML based on associative arra

2019-03-03 03:45发布

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:

enter image description here

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?

标签: php uml
1条回答
Viruses.
2楼-- · 2019-03-03 04:33

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

enter image description here

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

enter image description here

查看更多
登录 后发表回答