120x Filetype PDF File size 1.01 MB Source: yunus.hacettepe.edu.tr
Design Patterns Strategy Pattern* How to design for flexibility? ebru@hacettepe.edu.tr ebruakcapinarsezer@gmail.com http://yunus.hacettepe.edu.tr/~ebru/ @ebru176 Ekim 2017 *revised from, www.uwosh.edu/faculty_staff/huen/262/f09/slides/10_Strategy_Pattern.ppt Existing Duck application All ducks quack Duck and swim. The superclass takes quack() care of the swim() implementation The display() code display() method is abstract, //other duck-like methods… since all duck Each duck subtype is subtypes look responsible for different implementing its own display() method Other duck MallardDuck RedHeadDuck types inherit display() { from the display() { Duck class // looks like a mallard} // looks like a redhead } . . . Testing Mallard, RedHeadDuck classes Changing Requirment • No sweat! • Add a method fly() in Duck • Continue to use inheritance
no reviews yet
Please Login to review.