-->

Associative array in UML class diagram

2019-07-27 10:29发布

问题:

I have an array that I want to show in a class diagram.

protected static $config = array(
        'host' => 'localhost',
        'username' => '',
        'password' => '',
        'dbname' => ''
    ); 

is this a correct way :

$config( key: 'localhost', value: '', key: 'username', value: '', key: 'password', value: '', key: 'dbname', value: '')

and underlined the whole line for static

回答1:

Usually one doesn't use UML to configure things, but you can do it. You would need to create instance specifications to get the result you want.

You could create an instance specification, associativeArrayInstanceSpec1 of type AssociativeArray that composes a bunch of other AssociativeArrayEntry instance specifications that each have a specific key and value. Then you could declare a property with a default value in SomeClass as config : AssociativeArray [1] = associativeArrayInstanceSpec1.