0% found this document useful (0 votes)
11 views

L17Exercise-DesignPatterns

Uploaded by

hamzabjibji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

L17Exercise-DesignPatterns

Uploaded by

hamzabjibji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EXERCISE 1: PUT ON YOUR THINKING CAP

Which of the following are disadvantages of using


inheritance to provide Duck behaviour? (Choose all that apply.)
 A. Code is duplicated across subclasses.
 B. Runtime behaviour changes are difficult.
E.g., we cannot change the flying behaviour of a duck at runtime.
 C. We can't make ducks dance.
 D. Hard to gain knowledge of all duck behaviours.
E.g., we need to look at all the duck subclasses to determine all the
different quacking behaviours.
 E. Ducks can't fly and quack at the same time.
 F. Changes can unintentionally affect other ducks.
E.g., adding flying behaviour to the superclass allowed all ducks to
fly, even those that should not be able to fly.
EXERCISE 2: DESIGN PRINCIPLE CHALLENGE
How does the observer pattern use the following principles?

Design Principle
The number and types of
Identify the aspects of your observers vary; observers
application that vary and separate are separated from the state
them from what stays the same. of the subject.

Design Principle
Subjects and observers know
Program to an interface, each other via interfaces.
not an implementation.

Design Principle
Observers are composed with their
Favour composition subject; no inheritance is used.
over inheritance.

You might also like