前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >UML2.51边译边学-接口

UML2.51边译边学-接口

作者头像
面向对象思考
发布2021-10-14 16:16:13
4320
发布2021-10-14 16:16:13
举报

本文是UML规范2.5.1中接口相关部分中文翻译。原文可从https://www.omg.org/spec/UML/2.5.1下载。

10.4 Interfaces(接口)

10.4.1 Summary(总结)

Interfaces declare coherent services that are implemented by BehavioredClassifiers that implement the Interfaces via InterfaceRealizations.

接口声明由行为类目实现的一致服务,这些服务通过接口实现关系实现接口。

10.4.3 Semantics(语义)

10.4.3.1 Interfaces(接口)

An Interface is a kind of Classifier that represents a declaration of a set of public Features and obligations that together constitute a coherent service. An Interface specifies a contract; any instance of a Classifier that realizes the Interface shall fulfill that contract. The obligations associated with an Interface are in the form of constraints (such as pre- and postconditions) or protocol specifications, which may impose ordering restrictions on interactions through the Interface.

接口是一种类目,表示一组公共特性和义务的声明,这些特性和义务共同构成了一个连贯的服务。一个接口指定一个契约;实现接口的类目的任何实例都应履行该合同。与接口相关联的义务以约束(例如前置条件和后置条件)或协议规范的形式存在,它们可能会对通过接口的交互施加排序限制。

Interfaces may not be instantiated. Instead, an Interface specification is implemented or realized by a BehavioredClassifier, which means that the BehavioredClassifier presents a public facade that conforms to the Interface specification.

接口不能被实例化。相反,接口规范由行为类目实装或实现,这意味着 行为类目呈现符合接口规范的公共外观。

译者注:行为类目包括Actor,UseCase,Class,Collaboration

NOTE. A given BehavioredClassifier may implement more than one Interface and that an Interface may be implemented by a number of different BehavioredClassifiers.

注意:一个给定的行为类目可以实现多个接口,并且一个接口可以由许多不同的行为类目实现。

Interfaces provide a way to partition and characterize groups of public Features and obligations that realizing BehavioredClassifiers shall possess. An Interface does not specify how it is to be implemented, but merely what needs to be supported by realizing BehavioredClassifiers. That is, such BehavioredClassifiers shall provide a public façade consisting of attributes, Operations, and externally observable Behavior that conforms to the Interface.

接口提供了一种划分和表征实现行为类目应拥有的公共特征和义务组的方法。接口不指定它是如何实现的,而只是指定实现行为类目需要支持什么。也就是说,此类行为类目应提供一个公共外观,包括符合接口的属性、操作和外部可观察行为。

NOTE. If an Interface declares an attribute, this does not necessarily mean that the realizing BehavioredClassifier will necessarily have such an attribute in its implementation, but only that it will appear so to external observers.

注意:如果接口声明了一个属性,这并不一定意味着实现的行为类目在其实现中一定会有这样的属性,而只是它会出现在外部观察者面前。

The set of Interfaces realized by a BehavioredClassifier are its provided Interfaces, which represent the services and obligations that instances of that BehavioredClassifier offer to their clients. Interfaces may also be used to specify required Interfaces, which are specified by a Usage dependency between the BehavioredClassifier and the corresponding Interfaces. Required Interfaces specify services that a BehavioredClassifier needs in order to perform its function and fulfill its own obligations to its clients.

由行为类目实现的一组接口是其提供的接口,它们表示该行为类目的实例为其客户提供的服务和义务。接口也可用于指定所需的接口,这些接口由 行为类目相应接口之间的使用依赖项指定。必需的接口指定行为类目需要的服务,以便执行其功能并履行其对客户的义务。

Properties owned by Interfaces (including Association ends) imply that the realizing BehavioredClassifier should maintain information corresponding to the type and multiplicity of the Property and facilitate retrieval and modification of that information. A Property declared on an Interface does not necessarily imply that there will be such a Property on a realizing BehavioredClassifier (e.g., it may be realized by equivalent get and set Operations). Interfaces may also own constraints that impose constraints on the Features of the implementing BehavioredClassifier.

接口拥有的属性(包括关联端)意味着实现的行为类目应该维护与属性的类型和多样性相对应的信息,并促进该信息的检索和修改。在接口上声明的属性不一定意味着在实现行为类目上会有这样的属性(例如,它可以通过等效的 get 和 set 操作实现)。接口也可能拥有对实现行为类目的功能施加约束的约束。

Interfaces may own a ProtocolStateMachine that specifies event sequences and pre/post conditions for the Operations and Receptions described by the Interface. A BehavioredClassifier realizing an Interface shall comply with the ProtocolStateMachine owned by the Interface.

An Interface may be parameterized, bound, and used as TemplateParameters.

接口可能拥有一个协议状态机,它为接口描述的操作和接收指定事件序列和前置/后置条件。实现接口的协议状态机应符合接口拥有的协议状态机。接口可以被参数化、绑定并用作模板参数。

An InterfaceRealization relationship between a BehavioredClassifier and an Interface implies that the BehavioredClassifier conforms to the contract specified by the Interface by supporting the set of Features owned by the Interface, and any of its parent Interfaces. For BehavioralFeatures, the implementing BehavioredClassifier will have an Operation or Reception for every Operation or Reception, respectively, defined by the Interface. For Properties, the realizing BehavioredClassifier will provide functionality that maintains the state represented by the Property. While such may be done by direct mapping to a Property of the realizing BehavioredClassifier, it may also be supported by the StateMachine of the BehavioredClassifier or by a pair of Operations that support the retrieval of the state information and an Operation that changes the state information.

行为类目和接口之间的接口实现关系意味着行为类目通过支持接口拥有的功能集及其任何父接口来符合接口指定的契约。对于行为特征,实现行为类目将分别为每个操作或接收有一个操作或接收,由接口定义。对于属性,实现 行为类目将提供维护由属性表示的状态的功能。虽然这可以通过直接映射到实现行为类目的属性来完成,但也可以由行为类目的状态机或一对支持检索状态信息的操作和更改状态信息的操作来支持。

译者注:和行为特征相对的是结构特征(StructuralFeature)。

The InterfaceRealization dependency from ProximitySensor to ISensor is shown using ball (lollipop) notation (see Figure 10.8).

从 ProximitySensor 到 ISensor 的接口实现依赖性使用球(棒棒糖)表示法显示(请参阅图 10.8)。

译者注:想象成汽车等的档把更容易记住

Figure 10.9 shows the lollipop notation for an inherited provided interface.

图 10.9 显示了继承提供的接口的棒棒糖符号。

The Usage dependency from TheftAlarm to ISensor is shown using socket notation (see Figure 10.10).

从 TheftAlarm 到 ISensor 的 Usage 依赖关系使用套接字表示法显示(见图 10.10)。

译者注:想象成挂档的手更容易记住

Alternatively, in cases where Interfaces are represented using the rectangle notation, InterfaceRealization and Usage dependencies are denoted with appropriate dependency arrows (see Figure 10.11). The Classifier at the tail of the arrow implements the Interface at the head of the arrow or uses that Interface, respectively.

或者,在使用矩形符号表示接口的情况下,接口实现关系和使用依赖项用适当的依赖项箭头表示(见图 10.11)。箭头尾部的分类器分别实现箭头头部的接口或使用该接口。

It is often the case in practice that two or more Interfaces are mutually coupled through application-specific dependencies. In such situations, each Interface represents a specific role in a multi-party “protocol.” These types of protocol role couplings may be captured by Associations between Interfaces as shown in the example in Figure 10.12. This shows the specification of three Interfaces, IAlarm, ISensor, and IBuzzer. IAlarm and ISensor are shown as engaged in a bidirectional protocol, meaning that any implementation of ISensor must maintain the information needed to realize the theAlarm property, and similarly for IAlarm and theSensor. IBuzzer describes an Interface that implementers of IAlarm must be able to access.

实践中经常出现两个或多个接口通过特定于应用程序的依赖项相互耦合的情况。在这种情况下,每个接口代表多方“协议”中的特定角色。这些类型的协议角色耦合可以通过接口之间的关联来捕获,如图 10.12 中的示例所示。这显示了三个接口 IAlarm、ISensor 和 IBuzzer 的规范。IAlarm 和 ISensor 显示为参与双向协议,这意味着 ISensor 的任何实现都必须维护实现 theAlarm 属性所需的信息,对于 IAlarm 和 theSensor 也是如此。IBuzzer 描述了 IAlarm 的实现者必须能够访问的接口。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2021-10-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 面向对象思考 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档