Presentation is loading. Please wait.

Presentation is loading. Please wait.

WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.

Similar presentations


Presentation on theme: "WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010."— 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 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 Assume AddressBook is keeping track of all commands executed earlier
History Command execute() undo() add(Command) (a) 1 (b) 0..1 (c) * (d) 1..* mul {a|b|c|d} e.g. mul b OR tinyurl.com/answerpost

3 OOP: Intermediate Concepts

4 Collaborating objects
Some more rules How to structure? Object rules Collaborating objects Object structure Follow a paradigm OOP 1 2 3 4 1. Abstraction 2. Encapsulation 3. ………….. 4. ……………..

5

6 Student Book borrows Student Book borrowed by

7 Where to put return date?
Student Book borrows Where to put return date?

8 Association classes Student Book borrows Student Book borrows Loan
returnDate Association classes

9 Association classes Student Book borrows Student Book borrows Loan
returnDate Association classes Student Book Loan returnDate

10 Student Book borrows Loan returnDate Association classes

11 Student Book borrows Loan returnDate Association classes

12 Student Book borrows Loan returnDate Chapter

13 Student Book borrows Loan returnDate Composition Chapter

14 Shelf Student Book borrows Loan returnDate Composition Chapter

15 Composition Aggregation
Shelf Student Book borrows Loan returnDate Composition Chapter Aggregation

16 Composition Aggregation
Shelf Book Composition Chapter Aggregation

17 Composition Aggregation

18 Composition Aggregation

19 Composition Aggregation
Book Student borrows Loan returnDate Chapter Shelf Composition Aggregation

20 Composition Aggregation
Book Student borrows Loan returnDate Chapter Shelf Composition Aggregation

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

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

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

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

25 Class-level members Association classes Composition Aggregation foo
bar() Association classes Composition Aggregation

26

27

28 Collaborating objects
How to structure? Object rules Collaborating objects Object structure Follow a paradigm OOP 1 2 3 4 1. Abstraction 2. Encapsulation 3. ………….. 4. ……………..

29

30 Can it give the behavior we need?
Is this good to go? Can it give the object structure we need? Possibly. It follows the real world. History :History TextUi MSLogic Storage :TextUi :MSLogic :Storage Minefield :Minefield m2:Mine s3:Square s2:Square m1:Mine s1:Square s4:Square ? Square Mine Can it give the behavior we need?

31

32 The architect <iframe width="560" height="315" src="

33

34 [interactions between components for a given scenario]
UI [interactions between components for a given scenario] Sequence Diagrams

35 [interactions between components for a given scenario]
:UI operation returned value [interactions between components for a given scenario] Sequence Diagrams

36 :UI

37 :UI

38 :UI

39 :UI

40 :UI

41

42

43 SD for PC phone :PCPhoneUI User press key Shows digit ‘send’
Complete this Sequence diagram. System: PC Phone Actor: phone user MSS: 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

44 :UI

45 :UI

46 :UI :MSLogic

47 :UI :MSLogic

48

49 I want a foo() No. That’s against SRP!

50

51

52

53 :UI :MSLogic

54 :UI :MSLogic

55 :UI :MSLogic

56 :UI :MSLogic Reference frame

57 :UI :MSLogic

58 :UI :MSLogic

59 :MSLogic :Storage :History

60

61

62 Collaborating objects
How to structure? Object rules Collaborating objects Object structure Follow a paradigm OOP Object behavior 1 2 3 4 1. Abstraction 2. Encapsulation 3. ………….. 4. ……………..

63 76767 OR tinyurl.com/answerpost
Assume you are implementing a minesweeper game. Explain how you would eliminate the possibility of losing the game on the first click. first {answer} e.g. first blah blah blah feed2103 blah blah.. OR tinyurl.com/answerpost

64 * Admin foreach Student s: s.getGPA(); … UGStudent Student NGStudent
PGStudent

65 Inheritence * foreach Student s: s.getGPA(); … :UGStudent UGStudent
Admin Student NGStudent getGPA() PGStudent

66 Inheritence is a UGStudent Student NGStudent getGPA() PGStudent

67 Inheritence super class : sub class parent class : child class
base class : derived/extended class UGStudent Student NGStudent getGPA() PGStudent specialization generalization

68 77577 OR tinyurl.com/answerpost
How many of these show true inheritance? (d) (a) Camera Cat Tiger iPhone Wheel Telephone (b) Car Engine (c) Novel TextBook true {0|1|2|3|4} e.g. true 3 feed2103 blah blah… OR tinyurl.com/answerpost

69 Inheritence inheritance tree/hierarchy UGStudent UGStudent Student
NGStudent NGStudent NGStudent getGPA() PGStudent PGStudent

70 Java: Single class hierarchy
Object HelloWorld Square FilledSquare C++: Many class hierarchies

71 Java: Single class hierarchy
Multiple inheritance Java: Single class hierarchy Object Horse ? shark HelloWorld Square FilledSquare C++: Many class hierarchies

72 Interface Segregation Principle
No client should be forced to depend on a method it does not use. Do you show the same personality to all of these? Parents Friends BF/GF BF/GF BF/GF BF/GF

73 Interface Segregation Principle
No client should be forced to depend on a method it does not use. Do you show the same personality to all of these? Parents Friends BF/GF BF/GF BF/GF BF/GF

74 Interface Segregation Principle
No client should be forced to depend on a method it does not use. GradeCalculator Student getName() getCAP() getNationality() FeeCalculator

75 Interface Segregation Principle <<interface>>
No client should be forced to depend on a method it does not use. Java allows inheriting from multiple interfaces (but not from multiple classes). Student getName() getCAP() getNationality() <<interface>> Graded Payee GradeCalculator FeeCalculator

76 Interface Segregation Principle <<interface>>
No client should be forced to depend on a method it does not use. Java allows inheriting from multiple interfaces (but not from multiple classes). Student getName() getCAP() getNationality() <<interface>> Graded Payee GradeCalculator FeeCalculator

77 <<interface>>
interface Graded{ public String getName(); public double getCAP(); } interface Payee{ public String getNationality(); class Student implements Graded, Payee{ //… @Override public String getName(){ return name; } public String getNationality(){ return nationality; public double getCAP(){ return cap; Student getName() getCAP() getNationality() <<interface>> Graded Payee

78 <<interface>>
interface Graded{ public String getName(); public double getCAP(); } interface Payee{ public String getNationality(); class Student implements Graded, Payee{ //… @Override public String getName(){ return name; } public String getNationality(){ return nationality; public double getCAP(){ return cap; Student getName() getCAP() getNationality() <<interface>> Graded Payee

79 <<interface>>
Student ugs = new UGStudent(); GradeCalculator.calculate(ugs); FeeCalculator.calculate(ugs); Inheriting from an interface creates an ‘is a’ relationship too. We can substitute Student objects where Graded interface is expected. class GradeCalculator{ static void calculate(Graded g){ //... } Student getName() getCAP() getNationality() <<interface>> Graded Payee GradeCalculator FeeCalculator

80 Collaborating objects
How to structure? Object rules Collaborating objects Object structure Follow a paradigm OOP Object behavior 1 2 3 4 1. Abstraction 2. Encapsulation 3. Inheritance 4. ……………..

81


Download ppt "WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010."

Similar presentations


Ads by Google