200 likes | 330 Vues
Dive into the world of design patterns with Erik Peterson and John Pharo as they explore how to manage various bird behaviors, using ducks as a primary example. This guide introduces key concepts like the Interface Segregation Principle, Adapter Pattern, Decorator Pattern, and Command Pattern—equipping developers with tools to create flexible, interchangeable, and adaptable systems. By encapsulating object creation and traversal, and adapting behavior dynamically, this resource presents a thoughtful approach to software design while maintaining a fun tone throughout.
E N D
Design Patterns Removing Pain From Design Erik Peterson John Pharo
Interfaces Interface Segregation Principle
Adapter Pattern Translates the interface of a class into one that clients expect
What the flock? Now we need a way to count all of these birds…
DecoratorPattern Allows additional behavior to be added to a class dynamically
How to build a duck • Now we have two types: • Quackable • Countable
Factories Encapsulate object creation
Abstract FactoryPattern Used to represent a group of factories that can create a common element
About that flock… We need a way to go through the flock and check up on each bird, but how?
IteratorPattern Encapsulates how to navigate an aggregate sequentially without exposing its internal structure
Another way of changing behavior Different ducks behave in different ways Some might even migrate to different locales in the winter!
Template MethodPattern Allows an inherited class to change the behavior on a base class by implementing an abstract (or virtual) method on the base
CommandPattern Encapsulates requests, allowing the consumer to take in different types, as well as support redo/undo functionality
CommandPattern Three types of objects are involved: Command – implements an interface for executing an operation, and links a receiver to an action Receiver – knows how to perform the actual action Invoker – tells command to carry out the request
Feeding the Ducks The Command Pattern Way • Command – FoodProvider – takes in the receiver (a dispenser), which knows how to dispense food • Receiver – CornDispenser – does actual dispensing of food • Invoker – DuckFeeder – allows setting of the command, and calls execute on it
Me: cerikpete@gmail.com http://erikbase.blogspot.com