CS 494, Spring 2005 Object-Oriented Design

上传人:xx****x 文档编号:240562389 上传时间:2024-04-15 格式:PPT 页数:39 大小:277KB
收藏 版权申诉 举报 下载
CS 494, Spring 2005 Object-Oriented Design_第1页
第1页 / 共39页
CS 494, Spring 2005 Object-Oriented Design_第2页
第2页 / 共39页
CS 494, Spring 2005 Object-Oriented Design_第3页
第3页 / 共39页
资源描述:

《CS 494, Spring 2005 Object-Oriented Design》由会员分享,可在线阅读,更多相关《CS 494, Spring 2005 Object-Oriented Design(39页珍藏版)》请在装配图网上搜索。

1、 2001 T.HortonCS 494,Spring 2005Object-Oriented Design&Dev.On to DesignReminder:Analysis modelsEarlier we modeled requirements using.Class Diagrams:Known as the Conceptual ModelSometimes known as the logical model.Classes represent domain-level entities.(E.g.things in the users world.)Thus no classe

2、s for implementation-level things.Associations model domain-level relationships.(E.g.user-understood relationships between things in the users world.)Usually dont show navigation on associationsReminder:Analysis models(2)Use Cases and Sequence DiagramsScenarios in a Use Case can be represented by UM

3、L sequence diagramsObjects in the sequence diagram could be either:The system and the actors,or.Domain-level entities modeled in the conceptual model(a class diagram)Messages between objects are:Again,at a high-level of abstractionScenario descriptions become messagesReminder:Goals for designCreate

4、detailed“plans”(like blueprints)for implementationBuild these from requirements models so we are confident that all user needs will be metCreate design models before coding so that we can:Compare different possible design solutionsEvaluate efficiency,ease of modification,maintainability,etcUML Notat

5、ions for DesignSeveral UML notations provide various views of a designClass diagrams:Possibly created at two different levels of abstraction for design:Specification level:Classes model types,and we focus solely on interfaces between software modulesImplementation level:Think of this as a true“softw

6、are blueprint”.We can go directly to code from this model.Two types of Interaction Diagrams:Sequence diagrams and Collaboration diagramsUML Notations for Design(2)Sequence diagramsObjects will be variables implemented in codeMessages are operations(e.g.C+member functions)applied to objectsSequence d

7、iagrams thus show how a sequence of operations called between a set of objects accomplishes a larger taskSequence diagrams for a particular scenario help identify operations needed in classesThey also allow us to verify that a design can support requirements(e.g.a use-case scenario)UML Notations for

8、 Design(3)State diagrams(not covered,easy to learn)Models how a particular object responds to messages according to its stateFor a single object,show states and transitions between statesTransitions may be conditional based on a guard conditionMay show an action an object takes on transition,or also

9、 activity carried out within a stateOccasionally used to model a systems or subsystems behavior(not just one objects)UML Notations for Design(4)PackagesA simple notation that groups classes togetherPossible to use this to show contents of a subsystemShow dependencies between packagesShow visibility

10、of classes between packagesNot really a rich enough notation for diagramming software architecturesOther relationships beyond dependencies?No.Component DiagramsModels physical modules of code(e.g.files,DLLs,physical databases)Design ProcessThere are many different approaches to design,but here is so

11、mething typical.First,create a model of the high-level system architectureUML does not really provide a notation thisNext,use the conceptual class model to build a design-level class model or modelsHere well assume were just building an implementation-level class modelAlso,model dynamic behavior usi

12、ng interaction diagrams.Design Process(contd)Well use sequence diagrams with objects from the implementation-level class modelSequence diagrams show how design-level objects will carry out actions to implement scenarios defined as part of use-case analysisMessages between objects are member-function

13、 calls between objectsImportant:Only member-function calls are shown,but other language statements(e.g.assignments)are executed between calls(of course).Design Process(contd)Important:Development of class and sequence diagrams is iterative and concurrentWhen we create sequence diagrams for a new sce

14、narios,we discover classes and operations that need to be added to the class modelThe two models grow together.Neither is a complete view of the system.Other documentation in text form is often used to provide details about class diagrams and sequence diagramsSpecification-Level Class DiagramsHow do

15、es a design-level class diagram differ from a conceptual-level diagram?No longer just an external view!We are now modeling“how”not just“what”.This class diagram must document:Additional classesHow you will implement associationsMultiplicity,Navigability or Direction;Association classesAdditional Cla

16、sses in a DesignAre additional classes needed?Of course!In general.Design-level“internal”classesData manager classes.E.g.collection objects that were simply associations beforeFacilitator or helper classes that assist with complex tasks(e.g.ObservableComponent)Factory classes that assist in creating

17、 new objectsClasses to implement other design patternsIs there any guidance or strategy for determining these?Class Types in a Layered ArchitectureFrom Ambler,Sect.7.15-layer modelClasses only interact within layers,or as shown by arrowsDirection matters!Next slide describes thesePossible Design Cla

18、ss TypesUI classesBusiness/Domain classesImplement domain-objects from AnalysisData objects plus their behaviorsController/Process classesimplement business logic,collaborations between business objects and/or other controllerPersistence classesHow to store,retrieve,delete objectsHides underlying da

19、ta stores from rest of systemSystem classesWrap OS-specific functionality in case that changesController/Process LayerImplements business logicEncapsulate a business rule(see next slide)These often require interactions etc.between objects of different classesExample from a student course enrollment

20、system:When can a Student enroll in a Seminar?Depends on schedule,pre-requisites,other constraintsBusiness RulesBack to requirements engineering:What kinds of requirements do we define?Functional:the system must do XDomain objects:the system must manipulate things with these characteristics and rela

21、tionshipsAlso:policiesBusiness rule:a policy your SW must satisfyWhat a functional requirement“knows”about controls,guidelines,access control,restrictions,etc.Often likely to change!More on ControllersWhy not just put business logic into the Domain class?Business rules change.We want domain classes

22、to be reusable.In UI class?Then must use that UI to carry out this process.(Too tightly coupled.)How to find Controller classes?To start:consider one for each use-caseIf trivial or belongs in domain class,dont.Amblers Controller Class ExampleExample in Ambler,page 259Class:EnrollInSeminar(whats inte

23、resting about that name?)Has link to a Student objectAn instance given to SeminarSelector object(UI),which calls seminarSelected(seminar)on itIt tests if Student/Seminar combination is OKAn instance given to FeeDisplay object(UI),which makes sure user willing to payIf so,its verifyEnrollment()is cal

24、led to finalize enrollmentController Classes:Good OO?Violates a principle of the OO approach!Data and behavior kept together!Yes,but is this always the best solution?DVDs and DVD players-why not one unit?Cameras and film vs.disposable camerasConsider coupling,change,flexibilityController classes are

25、 an example of the Mediator design patternMediator or control classes might grow to become god classestoo much control,or too centralizedNext:Detailed Class Design Implementing AssociationsHow associations are implemented is affected by multiplicity.Where they are implemented depends on navigability

26、.In one class or in both?Until now we may not have worried about direction of associations.Thats fine!Often navigability cannot be determined until design phase.Often it changes as we do more design.In prototypes we often keep links bidirectional for flexibility.Implementing Associations(2)Often we

27、use class operations to hide implementation details of associationsgetters,setters,traversal functions,update functions,etc.Dont forget:in C+,in-line functions are efficientAlso,derived associations(or attributes)are implemented as member functions that calculate something that is not stored directl

28、y in the class.One-Way AssociationsIf an association should just be navigable in just one direction,use the“arrow form”of the UML association in your class diagram.In UML no arrows means two-way or bi-directional.For implementation,the“target”object becomes an attribute in the classIn C+,it could be

29、 stored as an embedded object or as a pointerIn Java,objects are always references variables(so embedded objects really are pointers)Consider using association name or role name from the class diagram to name this attributeMultiplicity and One-Way AssociationsIf the multiplicity is“1”or“0.1”then the

30、 attribute would be a pointer to an object of the target classE.g.attribute in class Phone:selectedLine:Line*If the multiplicity is“many”but has a fixed maximum,then use array of pointers(or objects)E.g.“3”,“0.3”,“2.4”If no fixed maximum,e.g.“1.*”or“0.*”,then use a collection object as an attribute

31、that stores an arbitrarily large number of pointers or objectsFor qualified associations use a hash-table or map object to associate key with target objectMultiplicity and One-Way Assoc.(2)Examples using the C+standard library.A vector class is like an array with no maximum capacityExample attribute

32、 in class Phone:linkedLines:vectorOther C+classes might be appropriate too:set,listArrays should only be used if you know the maximumNote:Your team might agree not to show the“*”to indicate pointers.Conventions vary.Implementing Two-Way AssociationsThree options,depending on your needsNote:Sometimes

33、 its OK if traversal in one direction is slower than the otherOption One:Just like one-way but in both classesAdvantages:Equally efficient in both directionsBut,requires more spaceAlso,updating links between objects is more complexOften a good idea to use member functions to handle updates to links.

34、Implementing Two-Way Assoc.(2)Option Two:In one class,Class A,implement just like one-way(see above)to access Class B objects.In second class,Class B,write an operation that uses some kind of search of all objects of Class A to find the one that points back to the current B object.Why?Saves space if

35、 access from B to A is very rareBut,requires there to be some place where all objects of Class A are storedImplementing Two-Way Assoc.(3)Option Three:Implement an Association ClassThis class will have only one instance,which stores all the links between objects of the two classesImplemented as two d

36、ictionary or map objectsOne points to Class A objects,the other to Class B objectsSearch of this object is used to find links for one objectExample of Assoc.ObjectA person works for one company.A company has many employees.If pointers are not“bi-directional”,then Works-For object must support effici

37、ent look-up of a Person object in order to find that objects company.Note:This is not a UML diagram!Flashback to previous slidesSlides on class diagrams had“unused slides”at the end.Lets look at some of those now.Association ClassesSometimes associations are“first-class”thingsThey have a life-time,s

38、tate,and maybe operationsJust like objects!Association classesSame name as the association because.They represent the same thing!Association Class ExampleWorld Cup ExampleWe need a system to handle the World Cup.Teams represent countries and are made up of 22 players.Countries qualify from zones,whe

39、re each zone is either a country or a group of countries.Each team plays a given number of games in a specific city.Referees are assigned to games.Hotel reservations are made in the city where the teams play.World Cup Problem:Class ModelReturn from flashbackImplementing Association ClassesImplementa

40、tion depends on multiplicityIf one-to-one,then it would be possible to.Put attributes and operations inside either objectOr,put them in a separate class thats linked to either objectIf one-to-many,then same choices as one-to-one,but do this for the object on the“many”endAgain,could be a separate obj

41、ect(see next case)If many-to-many,you need a separate class with an object instantiated for each linkExample of Association Class ImplementationConceptual-Level Class DiagramCorresponding Design-Level Class DiagramNotes on Example ImplementationNo direct link(pointer)in design or implementation betw

42、een ClassA and ClassB instances!But.Each instance of an AssocClass object is linked to exactly one ClassA object and also to one ClassB objectThis forms a 3-tuple for each conceptual-level link between a pair of ClassA and ClassB objectsNote multiplicities reflect concept level:One ClassA object is linked to 1-to-many AssocClass/ClassB pairs.Great!One ClassB object links to 0-or-one AssocClass/ClassA pairs.Yes!

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!