790 likes | 810 Views
Learn intermediate concepts in object-oriented programming, including object structure, collaboration, and following the OOP paradigm.
E N D
WARNING • These slides are not optimized for printing or exam preparation. These are for lecture delivery only. • These slides are made for PowerPoint 2010. They may not show up well on other PowerPoint versions. You can download PowerPoint 2010 viewer from here. • These slides contain a lot of animations. For optimal results, watch in slideshow mode.
Assume AddressBook is keeping track of all commands executed earlier Command History execute() undo() add(Command) (a) 1 (b) 0..1 (c) * (d) 1..* mul {a|b|c|d} e.g. mul b 77577OR tinyurl.com/answerpost
OOP: Intermediate Concepts CS2103/T, Lecture 4, Part 1, [Sep 2, 2016]
How to structure? Object rules Collaborating objects Object structure Follow a paradigm 1 2 3 4 OOP 1. Abstraction 2. Encapsulation 3. ………….. 4. ……………..
Some more rules How to structure? Object rules Collaborating objects Object structure Follow a paradigm 1 2 3 4 OOP 1. Abstraction 2. Encapsulation 3. ………….. 4. ……………..
borrows Book Student Book Student borrowed by
borrows Book Student Where to put return date?
borrows Book Student Book Student Loan returnDate borrows Association classes
borrows Book Student Book Student Loan Book Student Loan returnDate returnDate borrows Association classes
Book Student Loan returnDate borrows Association classes
Book Student Loan returnDate borrows Association classes
Book Student Loan Chapter returnDate borrows
Book Student Loan Chapter returnDate borrows Composition
Book Student Loan Chapter Shelf returnDate borrows Composition
Book Student Loan Chapter Shelf returnDate borrows Composition Aggregation
Book Chapter Shelf Composition Aggregation
Composition Aggregation
Composition Aggregation
Book Student Loan Chapter Shelf returnDate borrows Aggregation Composition
Book Student Loan Chapter Shelf returnDate borrows Aggregation Composition
Book Student Loan Chapter Shelf returnDate borrows Where to put total students?
Book Loan Chapter Shelf Student returnDate -totalStudents +getTotal() borrows You mean I can say Student.getTotal() ? Class-level members
Book Loan Chapter Shelf Student returnDate -totalStudents +getTotal() borrows You mean I can say Student.getTotal() ? OK. Can I say Student.totalStudents? Class-level members
Book Loan Student returnDate -totalStudents +getTotal() borrows Class-level members
foo bar() Composition Aggregation Association classes Class-level members
How to structure? Object rules Collaborating objects Object structure Follow a paradigm 1 2 3 4 OOP 1. Abstraction 2. Encapsulation 3. ………….. 4. ……………..
Can it give the object structure we need? Is this good to go? Possibly. It follows the real world. History :History TextUi MSLogic Storage :MSLogic :Storage :TextUi Minefield :Minefield ? Square s1:Square s2:Square s3:Square s4:Square m1:Mine Mine m2:Mine Can it give the behavior we need?
:UI Sequence Diagrams [interactions between components for a given scenario]
:UI operation returned value Sequence Diagrams [interactions between components for a given scenario]
SD for PC phone 1. User presses digit 2. System shows digit Repeat step 1-2 until telephone number is entered. 3. User press ‘send’ 4. System connects the call. Telephone conversation takes place. 5. User press ‘end’ 6. System disconnects the call Use case ends. :PCPhoneUI User loop [Until full number] press key Shows digit ‘send’ call connected ‘end’ call disconnected
:UI :MSLogic
:UI :MSLogic
No. That’s against SRP! I want a foo()