您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 市场营销 > IT技术讲座建模build-models
Today’sAgendaQuickReviewContinueonOCLBuildModelsUsingOCL1QuickReviewWhatissoftwarespecification?Whydoweneedformalspecification?2BuildingModelswithOCLIntroductionCompletingUMLDiagramsModelingTipsandHintsSummary3WhatIsaModel?Simplyput,amodelisahighlevelsystemdescription.Itconsistsofaconsistent,coherentsetofmodelelements,i.e.,artifactswritteninawell-definedmodelinglanguagesuchasUMLandOCL.4UMLandOCL(1)BothUMLdiagramsandOCLexpressionsarepartofamodel.Theyareconnectedbythecontextdefinition.NotethatOCLexpressionscanbewritteninatextualformatorattachedtotheUMLdiagramsdirectly.5ExampleLoyaltyAccountpoints:Integernumber:Integerearn(i:Integer)burn(i:Integer)isEmpty():BooleanTransactionpoints:Integerdate:Dateamount:Realprogram():LoyaltyProgramaccounttransactions10..*inv:transactions.card.owner-size()=1pre:i0init:Set{}init:0body:points=06AddingExtraInfoOCLexpressionscanaddextrainfo.toUMLdiagramsinthefollowingsituations:Elementsmightbeunder-specified.Businessrulesneedtobeincorporated.Interfacesneedtobepreciselydefined.Ambiguitymustberemoved.7BuildingModelswithOCLIntroductionCompletingUMLDiagramsModelingTipsandHintsSummary8DiscoveringConstraintsOCLexpressionscanbeusedtospecifyconstraintsonaclassdiagram,butwheredotheycomefrom?UniquenessConstraintsOptional&DynamicMultiplicitiesAssociationCycles9UniquenessConstraints(1)Recallthefollowinguniquenessconstraint:contextPersoninv:Person::allInstances()-isUnique(socSecNr)Question:Howtodetermineifthevalueofaattributeneedstobeunique?10UniquenessConstraints(2)Ingeneral,weshouldaskthequestion:“Shouldequalityimplyidentity?”Iftwopeoplehavethesamename,doesitmeantheyarethesameperson?Iftwopeoplehavethesamesocialsecuritynumber,doesitmeantheyarethesameperson?Onewaytoidentifyuniquenessconstraintsislookingfor“sharing”Ifaninstancecanbeshared,thenitisnotunique.11OptionalMultiplicity(1)Anoptionalmultiplicityindicatesthatanassociatedobjectmayormaynotexist.Theexistenceofanassociatedobjectoftendependsonthestateoftheobjectsinvolved.Inthiscase,itisnecessarytouseOCLconstraintstodescribepreciselywhentheoptionalassociationmaybeempty.12OptionalMultiplicity(2)Housevalue:MoneyPersonsocSecNr:Integersalary:MoneygetMortage(sum:Moneysecurity:House)Mortgageprincipal:MoneymonthlyPayment:MoneystartDate:DateendDate:Date0..*1housesownermortgages0..*security1borrower1mortgages0..*13inv:mortgages-notEmpty()implieshouses-notEmpty()DynamicMultiplicity(1)Adynamicmultiplicityisonethatneedstobedeterminedbasedonanothervalueinthesystem.Inthiscase,OCLexpressionscanbeusetopreciselyspecifyhowtodeterminesuchamultiplicity.14DynamicMultiplicity(2)FlightFlightnr:IntegeravailableSeats():IntegerAirplanenumOfSeats:Integer0..*1flightsplanePersonname:String0..*0..*flightspassengers15contextFlightinv:passengers-size()=plane.numOfSeatsAssociationCycles(1)Anassociationcycleconsistsofasetofclassesandassociationssuchthatonecanstartfromoneclass,navigatethroughtheassociations,andreturntothesameclass.Cyclesareoftenthesourceofambiguity.Thegeneralruleisthatcyclesshouldbecheckedcarefully,especiallywhenthemultiplicitiesarehigherthanone.16AssociationCycles(2)Housevalue:MoneyPersonsocSecNr:Integersalary:MoneygetMortage(sum:Moneysecurity:House)Mortgageprincipal:MoneymonthlyPayment:MoneystartDate:DateendDate:Date0..*1housesownermortgages0..*security1borrower1mortgages0..*17contextMortgageinv:borrower=security.ownerAssociationCycles(3)Instructor-Title-Number-Time-RoomCourse-GPA-ProbationStudentUndergraduateGraduateFaculty-Name-Building-Head-CollegeDepartment-teaching1-taughtby0..*-advisee*-advisor1-commitee3..5-gradcommitees0..*-enrolled5..25-taking3..5-transcript**-major1-majors1..*-waitingfor0..*-waitlist0..*-dept1-faculty1..**-required1..*-NamePerson-asinstructor0..1-person1ID-id11-prereq*-requiredfor**-courses1..*FromDrs.DwyerandHatcliff18AssociationCycles(4)19Thecycleallowsagraduatestudenttoteachandenrollaclassatthesametime.Therefore,itisdesirabletoimposethefollowinginvariants:contextCourseinvNoTeachingWhileEnrolled:enrolled-intersection(taughtBy.person)-isEmpty()AssociationCycles(5)Instructor-Title-Number-Time-RoomCourse-GPA-ProbationStudentUndergraduateGraduateFaculty-Name-Building-Head-CollegeDepartment-teaching1-taughtby0..*-advisee*-advisor1-commitee3..5-gradcommitees0..*-enrolled5..25-taking3..5-transcript**-major1-majors1..*-waitingfor0..*-waitlist0..*-dept1-faculty1..**-required1..*-NamePerson-asinstructor0..1-person1ID-id11-prereq*-requiredfor**-courses1..*FromDrs.DwyerandHatcliff20AssociationCycle(6)21Thewaitinglistofacourseshouldbeemptyunlesstheenrollmentisfull.contextCourseinvNoWaitingUnlessFull:waitList-notEmpty()impliesenrolled-size=25AssociationCycles(7)Instructor-Title-Number-Time-RoomCourse-GPA-ProbationStudentUndergraduateGraduateFaculty-Name-Building-Head-CollegeDepartment-teaching1-taughtby0..*-advisee*-advisor1-commitee3..5-gradcommitees0..*-enrolled5..25-taking3..5-transcript**-major1-majors1..*-waitingfor0..*-waitlist0..*-dept1-faculty1..**-required1..*-NamePerson-asinstructor0..1-person1ID-id1
本文标题:IT技术讲座建模build-models
链接地址:https://www.777doc.com/doc-2878152 .html