Download presentation
Presentation is loading. Please wait.
Published byCollin Lloyd Modified over 9 years ago
2
Systems Requirements SE 3821 Design? Algorithms CS 2852
3
Systems Requirements SE 3821 Design: SE 2811 Algorithms CS 2852
4
Systems Requirements SE 3821 Design: SE 2811 Algorithms CS 2852
5
Systems Requirements SE 3821 Design: SE 2811 Algorithms CS 2852 Design pattern: general, reusable solution to a commonly occurring problem in software design
7
An analogy: Problem: Workplace, home traffic pattern: travel to frequently accessed objects If objects scattered, flow of life is awkward Items forgotten, misplaced
8
An analogy: Problem: Workplace, home traffic pattern: travel to frequently accessed objects If objects scattered, flow of life is awkward Items forgotten, misplaced Solution: Waist-high shelves around at least part of main rooms in which people live & work They should be long, 22-40 cm deep Shelves or cupboard underneath Interrupt shelf for seats, windows, doors
11
//Duck daffy = new Duck(Duck.MALLARD, “daffy”); //Duck donald = new Duck(Duck.REDHEAD, “donald”); //Duck clyde = new Duck(Duck.DECOY, “clyde”); … public void swim() { if( type == REDHEAD || type == MALLARD ) // swim in circles else // do nothing; decoys just float } public void quack() { if( type == MALLARD || type == REDHEAD ) // real ducks quack else // do nothing; decoys don’t quack } SimUDuck v1
14
SimUDuck v2
15
Is inheritance always a solution? Code duplication?
16
What about multiple levels of abstraction? Here, the swim() and quack() behavior is defined, but not implemented, in Duck… …instead, swim() and quack() behaviors are implemented in a second level of abstract classes... …and finally inherited in concrete classes. SimUDuck v3 And what about a quiet, swimming Duck?
17
What about multiple levels of abstraction? Here, the swim() and quack() behavior is defined, but not implemented, in Duck… …instead, swim() and quack() behaviors are implemented in a second level of abstract classes... …and finally inherited in concrete classes. SimUDuck v3 And what about a quiet, swimming Duck? BUT: Multiple inheritance is not even allowed in Java!
18
What about multiple levels of abstraction? Here, the swim() and quack() behavior is defined, but not implemented, in Duck… …instead, swim() and quack() behaviors are implemented in a second level of abstract classes... …and finally inherited in concrete classes. SimUDuck v3 And what about a quiet, swimming Duck? BUT: Multiple inheritance is not even allowed in Java! (FYI: it IS allowed in C++, but is EVIL)
19
What about multiple levels of abstraction? Even more importantly, this leads to messy “class explosion”… SimUDuck v3
20
What about multiple levels of abstraction? Even more importantly, this leads to messy “class explosion”… Lesson: need other ways to use inheritance to solve this problem! Next class: solution SimUDuck v3
22
We eliminate implementation in abstract classes, and force concrete classes to supply it instead. …but now we’re back to the duplication of code problem that we saw in v2! SimUDuck v4
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.