ocl – the object constraint language in uml

上传人:第*** 文档编号:48805241 上传时间:2018-07-20 格式:PPT 页数:46 大小:265KB
返回 下载 相关 举报
ocl – the object constraint language in uml_第1页
第1页 / 共46页
ocl – the object constraint language in uml_第2页
第2页 / 共46页
ocl – the object constraint language in uml_第3页
第3页 / 共46页
ocl – the object constraint language in uml_第4页
第4页 / 共46页
ocl – the object constraint language in uml_第5页
第5页 / 共46页
点击查看更多>>
资源描述

《ocl – the object constraint language in uml》由会员分享,可在线阅读,更多相关《ocl – the object constraint language in uml(46页珍藏版)》请在金锄头文库上搜索。

1、OCL The Object Constraint Language in UMLOCL website: http:/www.omg.org/uml/Textbook: “The Objection Constraint Language: Precise Modeling with UML”, by Jos Warmer and Anneke Kleppe This presentation includes some slides by: Yong He, Tevfik Bultan, Brian Lings, Lieber.1History nFirst developed in 19

2、95 as IBEL by IBMs Insurance division for business modellingnIBM proposed it to the OMGs call for an object-oriented analysis and design standard. OCL was then merged into UML 1.1.nOCL was used to define UML 1.2 itself.2Companies behind OCLnRational Software, Microsoft, Hewlett- Packard, Oracle, Ste

3、rling Software, MCI Systemhouse, Unisys, ICON Computing, IntelliCorp, i-Logix, IBM, ObjecTime, Platinum Technology, Ptech, Taskon, Reich Technologies, Softeam3UML Diagrams are NOT Enough!nWe need a language to help with the spec.nWe look for some “add-on” instead of a brand new language with full sp

4、ecification capability.nWhy not first order logic? Not OO.nOCL is used to specify constraints on OO systems.nOCL is not the only one.nBut OCL is the only one that is standardized.4OCL fills the missing gap:nFormal specification language implementable.nSupports object concepts.n“Intuitive” syntax rem

5、inds OO programming languages.nBut OCL is not a programming language:qNo control flow.qNo side-effects.5Advantages of Formal ConstraintsnBetter documentationqConstraints add information about the model elements and their relationships to the visual models used in UMLqIt is way of documenting the mod

6、elnMore precisionqOCL constraints have formal semantics, hence, can be used to reduce the ambiguity in the UML modelsnCommunication without misunderstandingqUML models are used to communicate between developers, Using OCL constraints modelers can communicate unambiguously6Where to use OCL?nSpecify i

7、nvariants for classes and typesnSpecify pre- and post-conditions for methodsnAs a navigation languagenTo specify constraints on operationsnTest requirements and specifications7Example: A Mortgage System1.A person may have a mortgage only on a house he/she owns. The start date of a mortgage is before

8、 its end date.8OCL specification of the constraints: 1. context Mortgage context Mortgageinvariant: self.security.owner = self.borrower invariant: security.owner = borrower2. context Mortgage context Mortgage invariant: self.startDate =18context Room invariant: guests - size qA dashed note line conn

9、ecting to the context figure in the UML modelsnA constraint might have a name following the keyword invariant.11Example of a static UML ModelProblem story: A company handles loyalty programs (class LoyaltyProgram) for companies (class ProgramPartner) that offer their customers various kinds of bonus

10、es. Often, the extras take the form of bonus points or air miles, but other bonuses are possible. Anything a company is willing to offer can be a service (class Service) rendered in a loyalty program. Every customer can enter the loyalty program by obtaining a membership card (class CustomerCard). T

11、he objects of class Customer represent the persons who have entered the program. A membership card is issued to one person, but can be used for an entire family or business. Loyalty programs can allow customers to save bonus points (class loyaltyAccount) , with which they can “buy” services from pro

12、gram partners. A loyalty account is issued per customer membership in a loyalty program (association class Membership). Transactions (class Transaction) on loyalty accounts involve various services provided by the program partners and are performed per single card. There are two kinds of transaction

13、s: Earning and burning. Membership durations determine various levels of services (class serviceLevel).12LoyaltyProgramenroll(c:Customer)Servicecondition: Boolean pointsEarned: Integer pointsBurned: Integer description: String0*deliveredServicesMembershipLoyaltyAccountpoints: Integerearn(i: Integer)

14、 burn(i: Integer) isEmpty(): BooleanCustomer name: String title:String isMale: Boolean dateOfBirth: DateCustomerCardvalid: Boolean validForm: Date goodThru: Date color: enumsilver, gold printedName: String0*0*age(): Integerprogramownercard0*cardProgramPartnernumberOfCustomers: Integerpartners1*1*Ser

15、viceLevelname: StringavailableServices0*ordered 1*010*actualLevelTransaction points: Integer date:Dateprogram(): LoyaltyProgram0*transactionscardtransactions0*transactions0*BurningEarningDate $now: Date isBefore(t:Date): Boolean isAfter(t:Date): Boolean =(t:Date): Boolean111111111levelgeneratedBypar

16、tner1account13Using OCL in Class DiagramsLoyaltyAccountpoints: Integerearn(i: Integer)burn(i: Integer)isEmpty(): Boolean points = 0 points = pointspre - i class invariantpostcondition for burn operation result = (points=0) points = i and i = 0 precondition for burn operation points = pointspre + i i = 0 14Invariants on AttributesnInvariants on attributes: context Customer invariant agerestriction: age = 18context Cus

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号