Presentation is loading. Please wait.

Presentation is loading. Please wait.

Systems Requirements SE 3821 Design? Algorithms CS 2852.

Similar presentations


Presentation on theme: "Systems Requirements SE 3821 Design? Algorithms CS 2852."— Presentation transcript:

1

2 Systems Requirements SE 3821 Design? Algorithms CS 2852

3

4 SimUDuck v5 Another approach: Isolate behaviors that vary Encapsulate these as attributes Benefits: Eliminates implementation inheritance Prevents class explosion

5

6 Collections.sort() Why Comparator<>? How to use?

7 Collections.sort() Why Comparator<>? How to use? Benefit: comparison strategy is decoupled from the sort() method

8 MethodBehavior InsertionSort ? TreeSort ?

9 MethodBehavior InsertionSortO(n 2 ), easy to verify TreeSortO(n log n), but not guaranteed MergeSortO(n log n), guaranteed QuickSortO(n log n) w/ random pivot

10 Elements: Context: class that encapsulates, uses specific behavior Strategy: interface that defines the behavior ConcreteStrategy: implements a specific behavior

11

12

13

14

15 // create some behaviors SwimBehavior csb = new CircularSwimming(); QuackBehavior sqb = new StandardQuacking(); SwimBehavior rsb = new RandomFloating(); // daffy has circular swimming, std quacking Waterfowl daffy = new Duck(“daffy”, csb, sqb); // donald has random floating, std quacking Waterfowl donald = new Duck(“donald”, rsb, sqb); daffy.swim(); donald.quack();

16

17 public abstract class Waterfowl { private SwimBehavior swimBehavior; private QuackBehavior quackBehavior; private String name; // constructor public void Waterfowl(String name, SwimBehavior sb, QuackBehavior qb) { this.name = name; swimBehavior = sb; quackBehavior = qb; } // centralize implementation of behaviors in top-level classes // if possible; avoid duplication of behavior in subclasses. // Note we can make this method final to prevent subclasses from overriding it! public void swim() { swimBehavior.swim(); // invoke the specific behavior }...

18 Strategy is a Behavioral Design Pattern

19

20

21

22

23

24

25

26

27

28 Access Levels ModifierClassPackageSubclassWorld publicYYYY protected???? /*package*/???? privateYNNN

29 Access Levels ModifierClassPackageSubclassWorld publicYYYY protectedYYYN /*package*/YYNN privateYNNN

30

31

32


Download ppt "Systems Requirements SE 3821 Design? Algorithms CS 2852."

Similar presentations


Ads by Google