UML的通用机制(四)



Extensibility Mechanisms

 

The UML provides a standard language for writing software blueprints, but it is not possible for one closed language to ever be sufficient to express all possible nuances of all models across all domains across all time. For this reason, the UML is opened-ended, making it possible for you to extend the language in controlled ways. The UMLs extensibility mechanisms include

 

lStereotypes

lTagged values

lConstraints

 

A stereotype extends the vocabulary of the UML, allowing you to create new kinds of building blocks that are derived from existing ones but that are specific to your problem. For example, if you are working in a programming language, such as Java or C++, you will often want to model exceptions. In these languages, exceptions are just classes, although they are treated in very special ways. Typically, you only want to allow them to be thrown and caught, nothing else. You can make exceptions first-class citizens in your models ---- meaning that they are treated like basic building blocks ----by marking them with an appropriate stereotype, as for the classOverflow in Figure 2-22.

 

Atagged valueextends the properties of a UML stereotype, allowing you to create new information in the stereotypes specification. For example, if you are working on a shrink-wrapped product that undergoes many releases over time, you often want to track the version and author of certain critical abstractions. Version and author are not primitive UML concepts. They can be added to any building block, such as a class, by introducing new tagged values to that building block. In Figure 2-22, for example, the classEventQueue is extended by marking its version and author explicitly.

 

Aconstraintextends the semantics of a UML building block, allowing you to add new rules or modify existing ones. For example, you might want to constrain theEventQueue class so that all additions are done in order. As Figure 2-22 shows, you can add a constraint that explicitly marks these for the operation add.

 

Collectively, these three extensibility mechanisms allow you to shape and grow the UML to your projects needs. These mechanisms also let the UML adapt to new software technology, such as the likely emergence of more powerful distributed programming languages. You can add new building blocks, modify the specification of existing ones, and even change their semantics. Naturally, its important that you do so in controlled ways so that through these extensions, you remain true to the UMLs purpose ---- the communication of information.

 

扩展机制

UML提供的是写软件蓝图的标准化语言,但是它不可能是一个封闭的语言,它不可能在所有的时间里横跨所有的领域来充分的表达所有模型的所有可能的细微差别.因此,UML是开放式的,允许建模者在可控的方式内扩展这门语言.UML的扩展机制包括:

l版型

l标签

l约束

版型扩展UML的词汇表,允许建模者创建构建块的新类型,这个新类型是从已存在的类型中派生出来,但用来描述建模者的具体问题.例如,你正使用一门程序设计语言工作,比如Java或是C++,你需要构建异常模型,在这些语言中,尽管它们有专门的方式处理,异常仍然只是类.典型地,你只想抛出和捕捉异常,而不做任何其它事情.你可以让异常在你的模型中成为最好的居民--这意味着它们作为基础构建模块被对待--用一个恰当的版型来标识它们,如图2-22的溢出类.

标签扩展UML版型的属性,允许建模者在版型描述中创建新的信息.例如,如果你在一个可伸缩的产品上工作,随着时间的推移,经历了许多版本,你经常想跟踪某个版本和某些关键的抽象作者.版本和作者都不是UML原有的概念.通过引进新的标签,它们可以被加到任何构建模块中,比如类.例如,在图2-22中,类事件队列的版本和作者以扩展的形式被明确的标识出来.

约束扩展UML构建模块的语义,允许你增加新的规则或是修改已存在的规则.例如,你可能想约束事件队列类,以便所有增加的事件都按次序工作.就像图2-22所示,为新增操作增加一个明确地约束标识.

总体来说,这三个扩展机制允许建模者为了自己项目的需要塑造和扩展UML.这些机制也让UML能适应新的软件技术,例如更强大的分布式的程序设计语言的出现.建模者可能增加新的构建模块,修改已存在的构建模块的说明,甚至是改变它们的语义.当然,建模者在可控的方式内做这些是很重要的,以便通过这些扩展,建模者保持UML的真正目的--信息的沟通.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值