8.3.8 UML元类上的额外操作

在章节“抽象语法”、“具体语法”和“在UML模型中Ocl表达式的使用”中使用了许多UML元类上的其它操作。它们在本节进行定义。下一节定义OCL元类上的其它操作。

Classifier

操作commonSuperType产生两个分类符的最近超类。

context Classifier
def: commonSuperType (c : Classifier) : Classifier =
        Classifier.allInstances()->select (cst |
                c.conformsTo (cst) and
                self.conformsTo (cst) and
                not Classifier.allInstances()->exists (clst |
                        c.conformsTo (clst) and
                        self.conformsTo (clst) and
                        clst.conformsTo (cst) and
                        clst <> cst
                )
        )->any (true)

如下的操作被加到分类符上来检索属性和操作。

context Classifier
def: lookupProperty(attName : String) : Attribute =
        self.allProperties()->any(me | me.name = attName)
def: lookupAssociationClass(name : String) : AssociationClass =
        self.allAssociationClasses()->any (ae | ae.name = name)
def: lookupOperation (name: String, paramTypes: Sequence(Classifier)): Operation =
        self.allOperations()->any (op | op.name = name and op.hasMatchingSignature(paramTypes))
def: lookupSignal (sigName: String, paramTypes: Sequence(Classifier)): Signal =
        self.allReceptions().signal->any (sig | sig.name = sigName and
                                        sig.hasMatchingSignature(paramTypes))
def: allReceptions() : Set(Reception) =
        self.allFeatures()->select(f | f.oclIsKindOf(Reception))
def: allProperties() : Set(Property) =
        self.allFeatures()->select(f | f.oclIsKindOf(Property))
def: allOperations() : Set(Property) =
        self.allFeatures()->select(f | f.oclIsKindOf(Operation))

操作allFeatures()定义在UML语义中。

操作allInstances()

context Classifier
def: allInstances() : Set( T ) = -- all instances of self

返回该分类符及其特化的分类符的所有实例。只能用于具有有限数量实例的分类符。举个例子,用户定义的类(因为实例需要显示地被创建)、枚举、标准的布尔型,以及特殊类型像OclVoid就属于这种情况。而数据类型,像集合类型、标准的字符串、UnlimitedNatural、Integer和Real则不属于这种情况。

Operation

Operation上增加了一个额外操作,它检查其签名是否与一个分类符的序列相匹配。注意,在匹配过程中,只考虑输入参数。

context Operation
def: hasMatchingSignature(paramTypes: Sequence(Classifier)) : Boolean =
    -- check that operation op has a signature that matches the given parameter lists
    let sigParamTypes: Sequence(Classifier) = self.allProperties().type in (
        ( sigParamTypes->size() = paramTypes->size() ) and
        ( Set{1..paramTypes->size()}->forAll ( i |
            paramTypes->at (i).conformsTo (sigParamTypes->at (i)))
        )
    )
def: allProperties() : Set(Property) = self.ownedParameter->asProperty()

Parameter

操作asProperty产生一个属性,它具有与该参数相同的名称和类型等。

context Parameter::asProperty(): Property
pre: -- none
post: result.name = self.name
post: result.type = self.type
post: result.upperValue = 1
post: result.lowerValue = 1
post: result.isOrdered = true
post: result.isStatic = false
post: result.visibility = VisibilityKind::private

Parameter上还增加了一个类操作来返回一个参数。

context Parameter::make(n : String, c : Classifier, k : ParameterDirectionKind) :Parameter
post: result.name = n
post: result.kind = k
post: result.type = c

Property

如果所必比较的属性具有相同的名称和类型,那么操作cmpSlots返回真。

context Parameter::cmpSlots(): Boolean = --译者注:此处应为Property::cmpSlots()
    result.name = self.name and result.type = self.type

Signal

Signal增加了一个额外操作,它检查其签名是否与一个分类符序列相匹配。注意,在匹配过程中,信号的参数是它的属性。

context Signal
def: hasMatchingSignature(paramTypes: Sequence(Classifier)) : Boolean =
    -- check that signal has a signature that matches the given parameter lists
    let opParamTypes: Sequence(Classifier) = self.ownedParameter->select (p | p.kind <>
        ParameterDirectionKind::return).type in (
            ( opParamTypes->size() = paramTypes->size() ) and
            ( Set{1..paramTypes->size()}->forAll ( i |
                paramTypes->at (i).conformsTo (opParamTypes->at (i))
            )
        )
    )

State

操作getStateMachine()返回状态所属的状态机。

context State::getStateMachine() : StateMachine
post: result = container.stateMachine

Transition

操作getStateMachine()返回transition所属的状态机。

context Transition::getStateMachine() : StateMachine
post: result = container.stateMachine

results matching ""

    No results matching ""