UML for OCaml immediate objects

2019-07-07 08:48发布

I have created an immediate object in OCaml.

let x = 
object (self)
val dataMember = 3
method aMethod = print_endline "Called a method"
end;;

As the object doesn't have a name (is it considered anonymous?), how can it be correctly represented in UML?

Thanks.

2条回答
祖国的老花朵
2楼-- · 2019-07-07 08:58

You could give it a nonce-name, or some other formulaic value. "Correctly" in this context really just means something that will be clear. There is no "right answer" handed down from the International UML Standards Body or anything.

If you want a more concrete answer, why not call it something like Anonymous_foo_mungler where "foo_mungler" is replaced with the descriptive name you would have given it if it weren't anonymous.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-07-07 09:16

Here is what I found. I would just follow the image below (If you can), but first some discussion. Naming something in UML does not mean that it can't be anonymous in the implementation. I struggle more with that showing it "inside" the other class as difficult, thus the package/component inclusion line that is used below. You could also use an instantiate connection to show what you are looking for. You could also use components as they allow for inclusion. In the end though I am torn why you would model an anonymous class as it is not part of the structure in that you never reference it outside of the class (IN GENERAL), but more the behavior. Thus why instances and properties allow for anonymous elements. If you start modeling LISP etc this question gets really fun.

Up-to-date for UML 2.0: Anonymous class example
(source: informit.com)

Note that it is figure 3.22 and that the author says "Stereotype" which is incorrect as it is not part of the language so it is a keyword, which means not part of the formal model, any old string. Not all tools support the notation, but RSA/RSM does to my surprise, and uses something close to the notation.

Source Page - http://www.informit.com/articles/article.aspx?p=336264&seqNum=3

From the UML spec itself:

For properties - A property symbol may be shown containing just a single name (without the colon) in its name string. This implies the definition of an anonymously named class nested within the namespace of the containing class. The part has this anonymous class as its type. Every occurrence of an anonymous class is different from any other occurrence. The anonymously defined class has the properties specified with the part symbol. It is allowed to show compartments defining attributes and operations of the anonymously named class.

For Instances - (Names are optional for instances) The standard notation for an anonymous instance specification of an unnamed classifier is an underlined colon (‘:’). If an instance specification has a value specification as its specification, the value specification is shown either after anequal sign (“=”) following the name, or without an equal sign below the name. If the instance specification is shown using an enclosing shape (such as a rectangle) that contains the name, the value specification is shown within the enclosing shape.

查看更多
登录 后发表回答