用于javascript的UML? [英] UML for javascript?

查看:151
本文介绍了用于javascript的UML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种以图形方式表示javascript对象的方法...

I'm looking for a way of graphically representing javascript objects...

我知道有UML,但是例如,如何表示链接在两个对象之间,例如:

I know there is UML, but for example, how to represent the chain between 2 objects, eg:

var a, b;

a = {};
b = Object.create(a);

直观地说,我会画出这样的东西:

Intuitively, I'd draw something like this:

+-----+
|b    |
|-----|
|     |
+--+--+
   |     +-----+
   +---->|a    |
         |-----|
         |     |
         +-----+

但在UML中有不错的代表吗?

but is there a decent representation in UML?

那么 mixins 呢?

c = $.extend({}, a, b)

+-----+           +-----+
|a    |           |b    |
|-----|           |-----|
|     |<----------|     |
+-----+           +-----+
   +     +-----+
   |     |c    |
   |     |-----|
   +---->|     |
         +-----+


推荐答案

您需要知道的第一件事是JavaScript使用基于原型的继承。这意味着类和实例之间没有区别,就像其他OO语言(如Java)一样。只有对象。其中一个含义是区分对象图没有意义。

First thing you need to know is that JavaScript uses prototype-based inheritance. This means there is no distinction between classes and instances as in other OO languages (like Java). There are just objects. One implication of that is that differentiating between class and object diagrams does not make sense.

到第一个例子:

var a, b;

a = {};
b = Object.create(a);

这是继承 - 对象 b 继承属性对象 a

This is inheritance - object b inherits properties of object a.

在UML中对此进行建模的正确方法是此类/对象图:

Correct way to model this in UML is this class/object diagram:

可以将Mixins视为多重继承的形式,对象 c 从对象继承属性 a b ,图表可能如下所示:

Mixins can be viewed as a form of multiple inheritance, object c is inheriting properties from object a and b, diagram for that might look like this:

这篇关于用于javascript的UML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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