Documente Academic
Documente Profesional
Documente Cultură
Controller
Part 1 Part 2
6. Polymorphism
• Problem
• when related alternatives or behaviours vary by
object type, how should we handle that?
• Solution
• use polymorphic operations to assign the
responsibility for the different behaviours to the
types themselves
But what is the actual problem?
• conditional variation is a common aspect of many
programs
• and then apply the interface so that callers see a common steer() method:
• create adapter subclasses for each vehicle type (like the tax example)
• make each of them implement the Steerable interface and its steer()
method - which can make an internal call to the class’ own tailored
turning method
Comments
• a widely applicable pattern
• so don’t over-use
7. Pure Fabrication
• Problem
• however:
• PersistentStorage is cohesive ✓
• Solution
• balance
• navigability of design
• against
• Solution
• identify the points of variation or instability then
assign responsibilities to create an ‘interface’ around
them
• the different APIs of the external calculators are the points of instability
• the adapters protect the internal system objects from such variations
• by providing a stable interface object for them to collaborate with
Mechanisms Motivated by PV
• Core Mechanisms:
• data encapsulation
• interfaces
• polymorphism
• indirection
• an attribute of this
• the fix:
• http://en.wikipedia.org/wiki/
Software_design_pattern#Classification_and_list