如何用UML类图表示Javascript对象创建? [英] How to represent Javascript object creation with an UML class diagram?

查看:88
本文介绍了如何用UML类图表示Javascript对象创建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在为JavaScript APP绘制准确的UML类图时遇到了一些麻烦.我已经阅读了一些UML参考资源,但是仍然找不到适合我的情况的答案,因为所有示例都基于C ++/Java的经典继承和类模型.

I'm having some trouble drawing an accurate UML Class diagram for my JavaScript APP. I've read several UML reference resources, but still didn't find an answer for my situation, since all the examples are based on the classical inheritance and class model of C++/Java.

我想用构造函数和原型对象的扩展来表示自定义JavaScript对象的创建,这与C ++/Java类实例化完全不同.

I want to represent the creation of a custom JavaScript object with a constructor function and extension of it's prototype object, which is quite different from C++/Java class instantiation.

您如何用UML类图表示我的代码的简化版本?

How would you represent this simplified version of my code with an UML class diagram?

var Book = function(title, author) {
    this.title = title || 'No title specified';
    this.author = author || 'No author specified';
}

Book.prototype.isDigital = false;

Book.prototype.titleDisplay = function() {
    alert(this.title);
};

var theHobbit = new Book ("The Hobbit", "J.R.R. Tolkien");

注意:我的主要目的是在图中显示所有涉及的对象(Book,Book.prototype和theHobbit)之间是如何精确关联的,并显示原型中定义的参数与构造函数中定义的参数之间的关系.我知道我可以假装Book是一个经典"类,并像Java一样绘制它,从而简化了特定的JavaScript继承机制,但是我确信UML足够灵活,可以精确地描述我的情况.

NOTE: I'm especially aiming to show in the diagram how exactly all the involved objects (Book, Book.prototype and theHobbit) are related to each other and to show which parameters are defined in the prototype vs those defined in the constructor. I know I could just pretend Book is a "classical" class, and draw it like it was Java, simplifying the particular JavaScript inheritance mechanism, but I'm sure UML is flexible enough to describe precisely my case.

也许有专门针对JavaScript项目的UML指南吗?

Is there maybe a UML guide especially for JavaScript projects?

推荐答案

  • 让我们将主程序显示为A类.
  • 请保持课程以大写字母开头,成员以小写字母开头.还是很难读懂.
  • 很多事情很难说,不知道你的意思.这是一个图的存根:
  • 请阅读: https://stackoverflow.com/a/21551335/715269

    这篇关于如何用UML类图表示Javascript对象创建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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