Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object-Oriented Programming

Similar presentations


Presentation on theme: "Object-Oriented Programming"— Presentation transcript:

1 Object-Oriented Programming
OO Design Patterns Object-Oriented Programming

2 Simple SimUDuck app A duck pond simulation game
A large variety of duck species swimming and making quacking sounds Examples of duck species: mallards, red head ducks, mandarin ducks Đại học Công nghệ - ĐHQG HN OO Design Pattern

3 First Solution Đại học Công nghệ - ĐHQG HN OO Design Pattern

4 Then… ducks need to fly How to change the design?
Đại học Công nghệ - ĐHQG HN OO Design Pattern

5 What about rubber duckies?
Đại học Công nghệ - ĐHQG HN OO Design Pattern

6 What about decoy ducks? Đại học Công nghệ - ĐHQG HN OO Design Pattern

7 Disadvantage of using inheritance to provide Duck behavior?
A. Code is duplicated across subclasses. B. Runtime behavior changes are difficult C. We can’t make duck dances. D. Hard to gain knowledge of all duck behaviors E. Ducks can’t fly and quack at the same time F. Changes can unintentionally affect other ducks What do you think? Đại học Công nghệ - ĐHQG HN OO Design Pattern

8 Your solution? Đại học Công nghệ - ĐHQG HN OO Design Pattern

9 Using interfaces? What do you think about this design?
Đại học Công nghệ - ĐHQG HN OO Design Pattern

10 Separate things that vary from things that stay the same
Design Principle #1 Separate things that vary from things that stay the same Đại học Công nghệ - ĐHQG HN OO Design Pattern

11 Separating what varies from what stays the same
Đại học Công nghệ - ĐHQG HN OO Design Pattern

12 Program to an interface not an implementation
Design Principle #2 Program to an interface not an implementation Đại học Công nghệ - ĐHQG HN OO Design Pattern

13 Đại học Công nghệ - ĐHQG HN
OO Design Pattern

14 Examples Đại học Công nghệ - ĐHQG HN OO Design Pattern

15 Examples Programming to an implementation
Programming to an interface/superclass can assign the concrete implementation at run-time Đại học Công nghệ - ĐHQG HN OO Design Pattern

16 Behavior interfaces and classes
Other types of objects can reuse fly and quack behaviors We can add new behaviors w/o modifying any of the existing behavior classes or touching any of the Duck classes that use flying behavior Đại học Công nghệ - ĐHQG HN OO Design Pattern

17 Behavior interfaces and classes
Other types of objects can reuse fly and quack behaviors We can add new behaviors w/o modifying any of the existing behavior classes or touching any of the Duck classes that use flying behavior Đại học Công nghệ - ĐHQG HN OO Design Pattern

18 Behavior interfaces and classes
Other types of objects can reuse fly and quack behaviors We can add new behaviors w/o modifying any of the existing behavior classes or touching any of the Duck classes that use flying behavior Đại học Công nghệ - ĐHQG HN OO Design Pattern

19 Superclass Duck Đại học Công nghệ - ĐHQG HN OO Design Pattern

20 Superclass Duck Đại học Công nghệ - ĐHQG HN OO Design Pattern

21 Duck’s Subclasses Đại học Công nghệ - ĐHQG HN OO Design Pattern

22 Setting Behavior dynamically
How? Đại học Công nghệ - ĐHQG HN OO Design Pattern

23 Favor composition over inheritance
Design Principle #3 Favor composition over inheritance Đại học Công nghệ - ĐHQG HN OO Design Pattern

24 The pattern Đại học Công nghệ - ĐHQG HN OO Design Pattern

25 Homework Đại học Công nghệ - ĐHQG HN OO Design Pattern


Download ppt "Object-Oriented Programming"

Similar presentations


Ads by Google