1 / 86

WARNING

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 .

field
Download Presentation

WARNING

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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.

  2. A code extract from a past CS2103 project (similar to yours) Commandcmd= createCommand(commandString); cmd.exectute(); history.add(cmd); … cmd.undo(); Command History execute() undo() add(Command) (a) 1 (b) 0..1 (c) * (d) 0 mul {a|b|c|d} e.g. mul b 77577

  3. Commandcmd= createCommand(commandString); cmd.exectute(); history.add(cmd); … cmd.undo();

  4. Advanced OO concepts CS2103/T, Lecture 6, Part 1, [Sep 20, 2013]

  5. Advanced OO concepts

  6. Advanced OO concepts Abstraction Encapsulation …………………… …………………….

  7. Advanced OO concepts Abstraction Encapsulation …………………… …………………….

  8. borrows Book Student Book Student borrowed by

  9. borrows Book Student Where to put return date?

  10. borrows Book Student Book Student Loan returnDate borrows Association classes

  11. borrows Book Student Book Student Loan Book Student Loan returnDate returnDate borrows Association classes

  12. Book Student Loan returnDate borrows Association classes

  13. Book Student Loan Chapter returnDate borrows

  14. Book Student Loan Chapter returnDate borrows Composition

  15. Book Student Loan Chapter Shelf returnDate borrows Composition

  16. Book Student Loan Chapter Shelf returnDate borrows Composition Aggregation

  17. Book Chapter Shelf Composition Aggregation

  18. Composition Aggregation

  19. Composition Aggregation

  20. Book Student Loan Chapter Shelf returnDate borrows Aggregation Composition

  21. Book Student Loan Chapter Shelf returnDate borrows Aggregation Composition

  22. Book Student Loan Chapter Shelf returnDate borrows Where to put total students?

  23. Book Loan Chapter Shelf Student returnDate -totalStudents +getTotal() borrows You mean I can say Student.getTotal() ? Class-level members

  24. 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

  25. Book Loan Student returnDate -totalStudents +getTotal() borrows Class-level members

  26. Abstraction Encapsulation …………………… …………………….

  27. Example 1 I want to calculate average age of Students Here you go! UGStudent Admin NGStudent PGStudent

  28. Example 1 Gaaah….! UGStudent Admin NGStudent PGStudent

  29. Example 1 foreachStudent s: s.getAge(); … Can? Cannot! UGStudent Admin NGStudent PGStudent

  30. Example 2 Storage s; … s.load(); … Logic Storage

  31. Example 2 How? TestDriver Logic Storage StorageStub

  32. Example 2 TestDriver Logic Storage StorageStub Dependency Injection

  33. Example 2 Storage s; … s.load(); … TestDriver Logic Storage StorageStub setStorage(Storage) Storage s; … void setStorage(Storage s){ this.s = s; } Dependency Injection

  34. Example 2 Storage s; … s.load(); … TestDriver Logic Storage StorageStub setStorage(Storage) Storage s; … void setStorage(Storage s){ this.s = s; } Dependency Injection

  35. Treat one type as another and still get the behavior of the actual object Example 1 Example 2 foreachStudent s: s.getAge(); … TestDriver Logic Storage setStorage(Storage) StorageStub UGStudent Storage s; … void setStorage(Storage s){ this.s = s; } Admin NGStudent PGStudent

  36. Treat one type as another and still get the behavior of the actual object Example 1 Example 2 foreachStudent s: s.getAge(); … TestDriver Logic Storage setStorage(Storage) StorageStub UGStudent Storage s; … void setStorage(Storage s){ this.s = s; } Admin NGStudent Polymorphism PGStudent

  37. Polymorphism

  38. Different game, different behavior Same hardware/ software Polymorphism

  39. = ability to take many forms Polymorphism

  40. 2 1 Polymorphism Polymorphism

  41. 2 1 Polymorphism

  42. 2 1 Inheritance

  43. 2 1 Inheritance foreachStudent s: s.getAge(); … UGStudent * Admin Student NGStudent getAge() PGStudent

  44. 2 1 Inheritance foreachStudent s: s.getAge(); … :UGStudent UGStudent * Admin Student NGStudent getAge() PGStudent

  45. 2 1 Inheritance is a UGStudent Student NGStudent getAge() PGStudent

  46. How manyof these show true inheritance? Cat Tiger (a) Animal Dog (d) Camera Wheel (b) iPhone Car Telephone Engine (c) Book Novel TextBook true {0|1|2|3|4} e.g. true 3 77577

  47. 2 1 Inheritance superclass :subclass parentclass :childclass UGStudent Student NGStudent getAge() PGStudent specialization generalization

More Related