Download presentation
Presentation is loading. Please wait.
Published byLeonard Blankenship Modified over 9 years ago
1
Kate Gregory1 Week 3 Lab 1 due now Finding Classes in your System CRC Cards Collaboration Diagrams Lab 2
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 diaglab 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
Need Meeting Space? If you are having trouble finding a quiet place for group work, the library offers study rooms you can book for up to two hours… Kate Gregory
4
Imagine Cup Student programmer competition sponsored by Microsoft Very generous prizes Great opportunity to meet industry professionals and experience reality of software development http://imaginecup.com/ Kate Gregory4
5
5 What Classes does the system have? Finding the classes in your system is the first step in analysis and design These classes will encapsulate your business logic and will live in the business layer(s) Some people think of it as looking at all the “stuff” and sorting it into classes Others look at it as making up classes and then thinking of examples of them
6
Kate Gregory6 Techniques for finding classes Thinking about classifications Looking through use cases for nouns Considering common patterns Class responsibilities collaboration (CRC) analysis Collaboration diagram
7
Kate Gregory7 Grady Booch says…... Intelligent classification is intellectually hard work, and it best comes about through an incremental and iterative process... There is no such thing as the perfect class structure, nor the right set of objects. As in any engineering discipline, our design choice is compromisingly shaped by many competing factors.
8
Kate Gregory8 Classification Theory Classification is the process of checking to see if an object belongs to a category or a class Most humans find classification irresistible
9
Kate Gregory9 Objects and Classes A class is a specification of structure, behavior, and the description of an object. –An object is an instance of a class Classification is more concerned with identifying classes than identifying the individual objects in a system. Intelligent classification is intellectually hard work and may seem rather arbitrary.
10
Kate Gregory10 Use-case Driven Approach Describe the system Look at the words in the description or steps of each scenario Classes and objects needed for the scenario will present themselves to you
11
Kate Gregory11 Use case example - Banking Customer Withdraws Money A. Client provides Teller amount of withdrawal and account B. Teller checks balance in account and status of account C. Teller reduces balance of account by withdrawal amount D. Teller gives money to customer
12
Kate Gregory12 Banking use case cont. At B, if balance is lower than amount to be withdrawn, teller refuses transaction. Customer may return to A with a lower amount, or use case may end At B, if account is frozen, teller refuses transaction. Use case ends. At D, if customer leaves without money, teller reverses transaction and returns money to drawer
13
Kate Gregory13 Bank Nouns Client Teller Amount Account Balance Status Withdrawal Money Transaction Customer Hold Drawer
14
Implied Data Look for verbs in the use case that imply storage and retrieval of data –The clerk looks up the reservation –The receptionist records the appointment on the calendar The nouns in these sentences are almost certainly classes This is the information that passes between use cases Kate Gregory14
15
Kate Gregory15 Syntactic Lexical Analysis Read use cases, interviews, and requirements, looking for nouns and noun phrases –Mark verbs too; you’ll need them later Make a list –Change all plurals to singular –Drop irrelevant nouns –Combine synonyms –Establish if a noun is a class or an attribute
16
Kate Gregory16 Drop Irrelevant Classes Scrap candidate classes that have nothing to do with the system under study –Out of scope –Represent an actor But be aware of info about an actor –Nouns not related to the system
17
Kate Gregory17 Redundant Classes Do not keep two classes that express the same information. If more than one word is being used to describe the same idea, select the one that is the most meaningful in the context of the system. –Customer / Client / Member / Purchaser –Reservation / Booking / Prearranged Stay Remember to use the language of the user
18
Kate Gregory18 Adjective Classes Adult Membership, Youth Membership Checking Account, Savings Account Does the adjective change the behaviour of the object represented by the noun? –If the use of the adjective signals that the behaviour of the object is different, then make a new class. –If not, keep a single class and add the type as an attribute It is difficult for an object to change its class (you make a whole new object and copy values) but it’s easy to change an attribute –Can you convert a savings account to a checking account? If not, it’s more likely they are different classes
19
Kate Gregory19 Attribute or Class? Candidate classes which are used only as values should be defined or restated as attributes and not as a class. Example: age, salary, description. If it doesn't do anything, just holds information, it's usually not a class
20
The Power of Words
21
Kate Gregory21 Statement of Purpose Each class must have a purpose, must do something, not just hold information You must be able to formulate a statement of purpose for each candidate class –The Account class holds and manages information about a customer's money –The EmployeeInformation class holds salary and contact information and performs payroll calculations No statement of purpose? Not a class
22
Kate Gregory22 Common Class Patterns Tangible Things and Devices Concepts Events People Places Organization Communicating with Actors Information about Actors
23
Kate Gregory23 CRC Cards CRC stands for Class, Responsibilities and Collaborators developed by Cunningham, Wilkerson and Beck. CRC analysis helps you to –identify classes you need –Work out which responsibilities each class will have –Test your analysis
24
Kate Gregory24 CRC Process
25
Kate Gregory25 Collaborations An object can accomplish either a certain responsibility itself, or it may require the assistance of other objects. –Does it know all it needs to know to do it? If it requires the assistance of other objects, it must collaborate with those objects to fulfill its responsibility.
26
Kate Gregory26 Collaborations Invoice asks customer to print itself Invoice asks invoice items to print themselves Schedule asks task for its effort Schedule sets task’s start date
27
Kate Gregory27 CRC Cards CRC cards are 4" x 6" index cards. All the information for an object is written on a card. ClassName Collaborators... Responsibilities
28
Kate Gregory28 Manages balance Processes withdrawal Processes deposit Transaction log Savings Account Adds Transaction Deletes Transaction Knows list of Transactions Transaction Log One way
29
Kate Gregory29 Calculates total Prints paper invoice Updates inventory Customer, Line Item Inventory, Line Item Invoice Line Item
30
Kate Gregory30 How do you create them? Start with one or two obvious cards. If the situation calls for a responsibility not already covered by one of the classes: –Add a responsibility to a class, or –Create a new class to address that responsibility. Information held is a responsibility: “knows” or “manages” Don’t create an exhaustive list of attributes –Just say “manages contact info” for now Keep going until you can cover all the behaviour you listed in the use cases
31
Kate Gregory31 Collaboration diagram One box for each class, all on one diagram One line between boxes for each collaboration Arrow shows direction Savings account Transaction log
32
Kate Gregory32 Two kinds of collaboration diagram
33
Kate Gregory33 Overview collaboration diagram
34
Kate Gregory34 Using Collaboration Diagrams to explain relationships C++ managed C++CRT, STL, etc One call to foo() Hundreds of calls C# or C++ managed C++CRT, STL, etc One call to foo() Hundreds of calls C#C++CRT, STL, etc Hundreds of calls C++ One call to foo() One call
35
Testing your CRC Cards Go through the use cases Map sentences in the use cases to responsibilities on your cards –“Clerk records start and end date” Yes, we have a class responsible for keeping that –“Clerk calculates invoice total” Yes, we have a class responsible for calculating that –etc Kate Gregory35
36
36 Naming Classes The class should describe a single object, so it should be the singular form of the noun. –If you think you need Employee and Employees, try Employee and ListOfEmployees for now Use names that the users are comfortable with. The name of a class should reflect its intrinsic nature. –Not a CS concept like hash table, heap, stack –Queue and list are ok in their informal meanings
37
Kate Gregory37 Summary Finding classes is not easy. You get better with practice. There is no such thing as one “right set of classes.” Finding classes is an incremental and iterative process. Filling out the contents of proposed classes helps you to find more, or to gain confidence in the ones you have.
38
Kate Gregory38 Summary Unless you are starting with a lot of domain knowledge, you are probably missing more classes than you will eliminate. Naming a class is important. The class should describe a single object, so it should be a singular noun or an adjective and a noun.
39
Kate Gregory39 Lab 2 You are given a list of nouns Reject those that are not classes Add more if you feel some are missing Write a statement of purpose for all you keep Make a CRC card for all you keep Make an overview collaboration diagram that summarizes all the collaborations at once
40
Kate Gregory40 Next Time Read up to where we are Lab 2 will be due at the start of class –I will try to have Lab 1 marked for you If you want to read ahead, next lecture we start class diagrams
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.