ECS510 Algorithms and Data Structures in an Object-Oriented Framework (“ADSOOF”)
The Ducks example
This is the code, given as Java files, from John Brewer's paper Why a Duck?.
quack()
Duck1
quack()
Duck1
and DuckCall1
quack()
quack()
annotated to implement
Quackable
quack()
annotated to implement
Quackable
Quackable
used to call
quack()
on two objects of different classes which implement
Quackable
Quackable
objects from a static
factory method
QuackFactory1
Quackable
object to count
the number of calls of the quack()
method
QuackDecorator
Quackable
objects from a static
factory method
QuackFactory2
Quackable
objects,
implements Quackable
, and implements quack()
by
calling quack()
on all the Quackable
objects
in the collection
QuackComposite
quack()
method but does have a
honk()
method
Quackable
by converting
a quack()
call to a honk()
call
GooseAdapter
Quackable
by a quack()
call which does nothing
NullQuackable
and the other classes
introduced here
Here are some more files, which weren't in the Brewer paper, but use the same example to demonstrate another design pattern concept, the Factory Object:
Quackable
objects with a name set by the factory
QuackFactory3
Film buffs will, of course, know, but in case you were wondering, the title of Brewer's paper comes from what is perhaps the most well-known scene in any of the Marx brothers' films. It is in the film “The Cocoanuts”, script here, clip here.
Last modified: 16 July 2019