Download presentation
Presentation is loading. Please wait.
Published byLorena Chase Modified over 9 years ago
1
Kate Gregory1 Week 4 Lab 2 due now Why document? Unified Modeling Language Class diagrams
2
DateWeekTopicHand OutDue BackTest 6-Sep-131Administrivia / Overview / Motivation, benefits of OO 13-Sep-132Use CasesLab 1: Use cases 20-Sep-133CRC Cards, collab graphsLab 2: CRC cardslab 1 5% 27-Sep-13 4start class diag lab 2 5% 4-Oct-135Finish class diag, AssociationsLab 3: Class Diag 11-Oct-136Inh & Polymorphism / midterm reviewlab 3 5% 18-Oct-137midtermMidterm 25% 25-Oct-13Reading Break 1-Nov-138Interaction diag / Design PatternsLab 4: Interaction Diag 8-Nov-139Good Design / Modules & Packages / Deployment and component diagrams /Metrics / SOLID Lab 5: Critiqueslab 4 5% 15-Nov-1310State diagrams / Activity diagrams / Summary and Conclusion / The Future 22-Nov-1311Critiquescritique lab (before class) 15% 29-Nov-1312Critiques TBDFinal ExamFinal 40%
3
See Me At the break I need to see anyone who did not hand in Lab 1 Kate Gregory3
4
4 Why document? To make yourself think To provide a reference –For yourself during this project –For your coworkers –For yourself after the project is over For your client For your manager
5
Kate Gregory5 Documenting makes you think Does that class really know everything required for that calculation? Do these attributes belong together in a single class? Does that method really belong in that class?
6
Kate Gregory6 Documentation is useful What were the methods in this class again? Is balance an integer or a floating point number? What are the arguments to print()? Is that class called Employee or Worker? When and for whom? –You now, others now, you later
7
Kate Gregory7 Documentation releases money Clients approve cheques at milestones; documentation proves they’ve been reached Clients use documentation to confirm that a project is headed for success Managers use documentation to prove that work has been done and is headed for success
8
Kate Gregory8 Unified Modeling Language A model is an abstract representation of a system, constructed to understand the system prior to building or modifying it. The unified modeling language (UML) is a language for specifying, constructing, visualizing, and documenting the software system and its components.
9
Kate Gregory9 Who Unified What? Many authors developed notations for describing OO designs The unified modeling language (UML) was developed by Booch, Jacobson, and Rumbaugh and represents their agreement on notation It is now essentially the only formal notation used to document OO designs
10
Kate Gregory10 Static Object Model A static model can be viewed as a "snapshot" of a system's parameters at rest or at a specific point in time. The classes’ structure and their relationships to each other, frozen in time. Contrast to dynamic techniques covered later in this course such as sequence diagrams
11
Kate Gregory11 UML Class diagram The UML class diagram is the main static analysis diagram. Class diagrams show the static structure of the model. A class diagram is a collection of static modeling elements, such as classes and their relationships.
12
Kate Gregory12 Class Structure Employee Name: string MonthlySalary: int AnnualVacation: int RaiseSalary (int) PrintPaycheque ()
13
Kate Gregory13 Attributes and Methods Identify attributes and methods by analyzing use cases and CRC cards –CRC card may say “manages customer info”. You need to list attributes that make up “customer info” (use cases will help) and decide which have get/set methods, which are affected by “services” the class offers –Other responsibilities generally map to methods Attributes in top compartment –include the type (int, float) or meaning (dollars, degrees C) or both Methods in bottom compartment –May or may not list arguments or return types here
14
Kate Gregory14
15
Kate Gregory15 Finding Attributes Attributes usually correspond to nouns followed by possessive phrases such as cost of the soup. Keep the class simple; only state enough attributes to define the object state. Attributes are less likely to be fully described in the problem statement.
16
Kate Gregory Visibility Public + versus Private - –All attributes are private –During analysis, typically all methods are public Public attributes and methods can’t be removed or changed without breaking another’s code Ignore protected, friendly, package, internal and other language-specific visibilities during analysis
17
Visibility examples
18
Kate Gregory18 Gets and Sets For a private variable called Description, you can add a public method called GetDescription() –No arguments, return type is same as Description –This method will need to be supported even if you change the private variable (or completely remove it) later You might not always have a public SetDescription() method Some variables are managed by other methods –Deposit() and Withdraw() change balance –Does SetBalance() make sense? CRC cards remind you what other objects will need
19
Kate Gregory19 Gets and Sets Get means you are asking the object for information: tell me your balance, tell me your description Set means you are telling the object a new value for some information Use consistent nomenclature –GetDescription(), get_name(), getAddress(), Age() Neither get nor set must map to a single attribute
20
Kate Gregory20 No Derivable Attributes If age can be calculated from birth date, don’t store both age and birth date –extra memory consumed –extra work to keep them “in sync” Use get methods for both: one returns a simple value, the other calculates the answer
21
Kate Gregory21 More on Derivable Attributes Choose arbitrarily At any time you can change your mind, change the code for the get methods, and break no other code If there’s a performance problem, you can flip which is stored and which is calculated, even once the application is in production
22
Sharing an attribute Some attributes are specific to each instance of the class –The balance in Steve’s account –The balance in Jane’s account Some are shared by all the instances of the class –Interest rate –Service charge amounts (eg $1 for a withdrawal) Kate Gregory
23
Class Attributes No matter how many instances of the class (objects) exist, exactly one memory slot is used for the class attribute The value is shared by all the objects If it’s public, the value can be accessed even when no objects of the class have been created Avoids namespace issues and global variables (especially useful in languages that don’t allow globals) Avoids synchronization issues
24
Kate Gregory Class Methods Often used to access class attributes –Eg GetInterestRate(), SetInterestRate() Sometimes used to find/create instances Or for utilities, arithmetic, etc –you want to collect like methods together (sin, cos, tan, …) but no meaningful state for them to operate on Cannot access instance member variables –which instance’s ones would be used?
25
Kate Gregory Notation Both class attributes and class methods are underlined on the class diagram Various languages have keywords that apply to class attributes and methods –static –Shared static private int NumInvoices;
26
Class Attributes Underline class attributes or methods Rest of the notation is the same Kate Gregory
27
Class attribute All contracts have the same commission House for Sale Agent Client Contract Expirydate Commission: num
28
Kate Gregory28 Finding Methods How am I going to be used? How am I going to collaborate with other classes? How am I described in the context of this system's responsibility? What do I need to know? What states can I be in?
29
Kate Gregory29 Finding Methods Some methods are responsible for managing the value of attributes. Query, Update, Read, Write. Some methods provide the services of the class. CreditInterest, Deposit, PrintPayCheque. Use the responsibilities from the CRC cards
30
Kate Gregory30 Methods to Manage Data Class holds or knows a list of things? –Probably need methods to add/edit/delete/find items May need an initializer method to create a new instance of the class with all required data –Constructor –Specify minimal values needed to create a valid instance (can the name be blank? Can the birthdate be null?) May need a method to clean up departing objects –Destructor –Finalizer –Dispose Add these methods to the class diagram only if you see a need for them
31
Notation for Methods Parameter names and types Return types Some show in/out also
32
Why parameter names? Kate Gregory32
33
Methods and Parameters can make the boxes big
34
Kate Gregory34
35
Kate Gregory35 Omit Details if you must In class notation, either or both of the attribute and operation compartments may be suppressed. Boeing 737 length: meter fuelCapacity: Gal doors: int
36
Kate Gregory36 Current car: Car Objects are not Attributes On a class diagram, do not list attributes that are objects. Every person has a car, but not: Person BirthDate: Date travel () CurrentCar: Car
37
Kate Gregory37 Prepare to record relationships If another object appears to be an attribute, it’s actually a related class Next lecture’s topics will include ways to record these relationships
38
Kate Gregory38 Remember what class diagrams are for Reference –Names of classes –Names of methods –Parameters to methods –Names of attributes Excellent summary of decisions Visual understanding of the system
39
Kate Gregory39 For Next Lecture Read UML notation for a class diagram Read ahead for more on relationships between classes This lecture and next will be covered by Assignment 3 –Due Oct 11 th
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.