Presentation is loading. Please wait.

Presentation is loading. Please wait.

UML for design: Class Diagrams ENGR 110 #

Similar presentations


Presentation on theme: "UML for design: Class Diagrams ENGR 110 #"— Presentation transcript:

1 UML for design: Class Diagrams ENGR 110 #13 2016

2 UML What is the Unified Modeling Language?
A diagram language for specifying/describing many different aspects of a system. Helps in the process of design and implementation. Targeted to software systems, but many aspects are useful for other kinds of engineered systems also. Includes diagrams for Finite State Machines More expressive (and therefore complicated) than the diagrams we used. We will see five parts of UML: Object diagrams Class diagrams Use cases diagrams Sequence diagrams Activity diagrams For designing Object Oriented programmes For specifying the required behaviour of a system. All relevant beyond software systems. Part of the requirements analysis phase

3 A modelling language What is the value of these diagrams?
Why is it a “language”? Why is it important to draw the diagrams this way? A language is shared – makes communication easier A language helps you think EW Go EW Stopping NS Go carEW → NSamb → setTimer(3) carNS → EWamb → setTimer(3) timer → EWred → NSgrn NS Stopping timer → NSred → EWgrn

4 A modelling language What makes a Language: Simple view: Vocabulary
Grammar Rules Deeper view: “syntax” – rules about how to say/write/draw statements. most obvious aspect; least important aspect. “semantics” – how to interpret statements. critical for being precise and for communicating “ontology” – identifies important set of concepts, ideas, relationships makes distinctions that help you think

5 Language of FSM Diagrams
Ontology: there are states and transitions  distinction there are conditions for taking a transition there are actions Syntax: labelled circles, labelled arrows Semantics: how to interpret them EW Go EW Stopping NS Go carEW → NSamb → setTimer(3) carNS → EWamb → setTimer(3) timer → EWred → NSgrn NS Stopping timer → NSred → EWgrn

6 Designing programs Not a good idea to jump into coding a program without thinking first about the design of the program. COMP 102/112 didn’t talk much about design! we gave you the design of the programs – you just had to turn the design into code why? What does the design of a software system look like? How the system is broken down into components What the components do. COMP102 programs: classes, methods

7 Modularity Complexity Modularity
Central problem in most engineering tasks: Complexity Key technique to handle it: Modularity Break the task up into chunks chunks should be as independent as possible solve/design/build each chunk separately assemble them together Used in all branches of engineering

8 OO Design and Class Diagrams
Key principle in Object Oriented design for software systems: Primary Modularity = objects and classes Given a task, need to identify the different objects and classes that will make up the system what is in the objects and what they do how they are related and how they interact

9 OO Design and Class Diagrams
How? UML provides a language for this design step: object diagrams class diagrams  most common and most important UML diagram for design Ontological distinctions: objects attributes of objects associations/relationships between objects behaviour of objects classes of objects Start by identifying objects. Work out what we need to know about them.

10 The Frog game The FrogGame class is a simple game that lets a player try to hop their frogs to the other side of a three-lane road without being hit by the cars driving along the road.  Frogs start just below the road and have to hop to the far side (just past lane 4). Cars drive along the road at different speeds and with different sized gaps. The player has only one frog at a time, and can make it hop forward or back (one lane at a time). If the player gets a frog to the far side of the road, they gain 10 points, the frog hops off into the field, and the player gets another frog. When a frog is hit by a car, it dies, and the player gets a new frog if they have any lives left. The game keeps track of how many lives the player has left (initially 5) and the current score. The game ends when the player has run out of lives.

11 Object Diagram for FrogGame
name, type, What are the objects in the world: frog: Frog car1: Car car3: Car car2: Car nearSide: Lane lane3: Lane lane3: Lane lane2: Lane lane1: Lane lane2: Lane farSide: Lane

12 Object Diagram: attributes
name and type, attributes and values What are their attributes? frog: Frog lane = nearSide status = alive car1: Car lane = 3 direction = east position = 350 car3: Car lane = 1 direction = east position = 511 car2: Car lane = 2 direction = west position = 230 nearSide: Lane lane3: Lane lane1: Lane lane2: Lane farSide: Lane

13 Object Diagram for FrogGame
What are the associations between objects: frog: Frog status = alive car1: Car direction = east position = 350 car2: Car direction = west position = 230 car3: Car direction = east position = 511 lane lane lane lane nearSide: Lane lane3: Lane lane1: Lane lane2: Lane farSide: Lane

14 Object diagrams What is the ontology of Object diagrams? Objects:
entities in the world – frogs, buildings, books, people events – enrolment, return, transaction intangible entities – courses, companies, images roles – client, manager, member, surgeon entities that can do stuff – searcher, sorter, components – windows, buttons …. Attributes of objects information/values describing the objects (other than other objects) Associations (relationships) between objects

15 Object Diagram What happens when the problem gets bigger? Gets very messy!!! car9: Car lane: 1 direction: east position: 20 frog1: Frog lane: 0 status: alive car2: Car lane: 2 direction: west position: 230 car1: Car lane: 3 direction: east position: 350 frog2: Frog lane: 3 status: dead car8: Car lane: 2 direction: west position: 430 car4: Car lane: 2 direction: west position: 280 car5: Car lane:1 direction: east position: 260 car6: Car lane: 3 direction: east position: 30 car3: Car lane: 1 direction: east position: 511 car10: Car lane: 2 direction: west position: 120 car7: Car lane: 3 direction: east position: 300 frog3: Frog lane: 2 status: dead lane3: Lane lane1: Lane lane2: Lane

16 Class diagrams More useful for real design
Abstract from individual objects to classes of objects. What is the ontology of Class diagrams? Classes: categories of objects all of the same type, with the same behaviour Attributes of the objects in the classes Associations (relationships) between objects in the classes Actions/behaviour of objects in the classes Frog status: boolean lane

17 Class Diagrams Describe the categories of the objects, rather than the objects themselves: Notes Associations can have additional information on them Behaviour specifies the actions that can be done on the objects direction: string position: integer colour: Color speed: float Car class name, attributes incl associations behaviour Frog status: boolean lane lane Lane

18 Designing Class Diagrams
How do you work out what classes there should be? No mechanical algorithm: it is a design issue Starting point: the nouns/noun phrases in the specification eg, the initial text description, the use cases, etc. note: this is not enough: Some nouns don’t need to be classes Some classes aren’t explicitly mentioned in the specification.

19 Group Project sign-up system
System should allow students to sign up for group projects for their courses. Each course will have one or more group projects, and a number of projects per student. Each project will have a task, a lab place, a day, a maximum size, and a leader. A course administrator needs to be able to set up the projects for their course. Students should be able to specify the projects that they would like to do, and a preference order. When sufficient students have entered their preferences, the system should show which projects students are likely to be assigned to, along with the likelihood. The course administrator can “commit” to an allocation, at which point, the system will permanently allocate signed up students to projects. Students should be able to withdraw from projects, and enter new preferences, but they won’t be actually assigned until the next time the administrator “commits”. Administrators should be able to get lists of students in each project of their course.

20 What are the objects and classes?
Next lecture: techniques, and more details.


Download ppt "UML for design: Class Diagrams ENGR 110 #"

Similar presentations


Ads by Google