Download presentation
Presentation is loading. Please wait.
Published byJustin Blake Modified over 9 years ago
1
Kate Gregory Week 8 Midterm discussion Interaction / Sequence Diagrams Design Patterns RAII Lab 4
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
Marking Comments Kate Gregory Lab 3 Midterm
4
Kate Gregory Sequence Diagrams Also called interaction diagram and interaction sequence diagram Based on a use case instance Document the ways that objects co-operate Two dimensions: –down represents time passing –across represents different objects
5
Kate Gregory Sample Sequence Diagram
6
Kate Gregory Tips for Good Sequence Diagrams Give your objects good names –especially when two objects of the same class are featured Record the parameters and return values being sent Refer to your use case often
7
Kate Gregory Sequence Diagrams Clarify Responsibilities Invoice, Customer, and Line Item co- operate to print an invoice:
8
Kate Gregory Return arrows clarify meaning
9
Kate Gregory Show the flow of information
10
Kate Gregory Lifetimes can vary
11
Design Patterns Patterns provide a mechanism for capturing and describing commonly recurring design ideas that solve a general design problem.
12
Kate Gregory Singleton Classes (such as inventory or member list) must have one, and only one, object instance. Must be able to call a method and get either the new object, or if one already exists, a pointer to it.
13
Kate Gregory Singleton Make the constructor of the class private –not accessible outside of the class structure –How do you create an object? Have a public class method like Instance( ) –checks an internal class variable, _instance, of the class type. –if _instance is NULL, create new object and return it, else return _instance.
14
Kate Gregory Singleton – Code Example class Singleton { public: static Singleton* Instance(); private: Singleton(); static Singleton* _instance; }; Singleton* Singleton::_instance = 0; Singleton* Singleton::Instance() { if(_instance == 0) { _instance = new Singleton(); } return _instance; }
15
Singleton-itis Singleton is good in certain situations –Application settings, pools (eg db connections), inventory, etc Almost impossible to write a thread-safe version Can be overused –Unrecorded dependencies Kate Gregory
16
Façade “Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher- level interface that makes the subsystem easier to use.” - Design Patterns, Gamma et al.
17
Kate Gregory Façade Hide the many interfaces of a detailed, complex subsystem by inserting a single interface (façade) between the high level classes and the subsystem. Insulate the consumers of your system from all your details Prevent other programmers from consuming your system “wrongly”
18
Façade example
19
Composite Perfect for unstructured hierarchies –Chains vary in length Employee reports to another Employee, who reports to another … A container holds items, some of which are actually containers, holding more items, which might be containers… Kate Gregory
20
Composite Pattern
21
RAII Resource Acquisition is Initialization –Terrible name C++ concept –Applicable in many other languages Key is known lifetime of objects –And automatic cleanup Kate Gregory
22
RAII Example Imagine a FILE resource you can get from your operating system –Open(string filename) returns handle –Read(handle h) returns some bytes –Write(handle h, byte[] b) writes data into it –Close(handle h) closes it You must remember to close the file Kate Gregory
23
FileWrapper class Constructor takes file name, calls Open Keep handle in member variable Read and Write are member functions –No need to pass handle Destructor (in C++ - other names other languages) calls Close –Cannot be forgotten –Works even in the presence of exceptions Kate Gregory
24
RAII in General Constructor acquires a resource –Source of the name Destructor frees the resource Cannot forget Works with exceptions Incredibly powerful Kate Gregory
25
Lab 4 Draw a sequence diagram –One diagram –One path through one use case Read the hints! –They are based on troubles students had in the past Don’t be surprised if you think a LOT for a single page you hand in
26
Kate Gregory Next Week Modules and Packages, Metrics Lab 4 due Lab 5 will be handed out
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.