View
167
Download
2
Category
Tags:
Preview:
DESCRIPTION
presentation
Citation preview
CODE LIKE A NINJASTRUCTURAL DESIGN PATTERNS
SESSION RESOURCES
• Presentation session notes including link to this session, will be available on http://learningaboutfudge.blogspot.com
• All the source for this session is publically available at: https://github.com/SheepWorx/Training
• RSS Feed: http://learningaboutfudge.blogspot.com/feeds/posts/default?alt=rss
• Local Network: \\dmeyer-m\share\training\Code Like a Ninja
• Source was compiled using Visual Studio 2012
• http://www.gofpatterns.com/
Design Patterns
Creational Design PatternsStructural Design PatternsBehavioral Design Patterns
STRUCTURAL DESIGN PATTERNS
Definition
Structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships between entities. Structural patterns are for tying together existing function.
• Adapter
• Bridge
• Composite
• Decorator
• Façade
• Flyweight
• Proxy
STRUCTURAL DESIGN PATTERNS
ADAPTER PATTERN
• Acts as an intermediary between two classes
• Enables incompatible interfaces to work together
• Implements an interface known to its clients and provides access to an instance of class not known to its clients
ADAPTER PATTERN
ADAPTER PATTERN – BENEFITS
• Allows two or more incompatible objects to communicate and interact
• Improves reusability of older functionality
ADAPTER PATTERN – WHEN TO USE IT
• You want to use an existing class, and its interface does not match the interface you need.
• You want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that do not necessarily have compatible interfaces.
• You want to use an object in an environment that expects an interface that is different from the object's interface.
• Interface translation among multiple sources must occur.
ADAPTER PATTERN
See code example
COMPOSITE PATTERN
• Enables you to create hierarchical tree of varying complexity
Motivation
When dealing with Tree-structured data, programmers often have to discriminate between a leaf-node and a branch. The solution is an interface that allows treating complex and primitive objects uniformly.
COMPOSITE PATTERN
COMPOSITE PATTERN – BENEFITS
• Defines class hierarchies consisting of primitive objects and composite objects
• Makes it easier to add new kinds of components
• Provides flexibility of structure and a manageable interface
COMPOSITE PATTERN – WHEN TO USE IT
• You want to represent the whole hierarchy or part of the hierarchy of objects.
• You want clients to be able to ignore the difference between compositions of objects and individual objects.
• The structure can have any level of complexity, and is dynamic.
COMPOSITE PATTERN
See code example
DECORATOR PATTERN
• Enables you to add or remove functionality without changing the external appearance or function of the object
DECORATOR PATTERN
DECORATOR PATTERN – BENEFITS
• More flexibility than static inheritance.
• Avoids feature-laden classes high up in the hierarchy
• Simplifies coding because you write a series of classes, each targeted at a specific part of the functionality, rather than coding all behaviour into the object
• Enhances the object's extensibility because you make changes by coding new classes.
DECORATOR PATTERN – WHEN TO USE IT
• You want to add responsibilities to individual objects dynamically and transparently, that is without affecting other objects
• You want to add responsibilities to the object that you want to change in the future
• When extension by static sub-classing is impractical.
DECORATOR PATTERN
See code example
SESSION RESOURCES
• Presentation session notes including link to this session, will be available on http://learningaboutfudge.blogspot.com
• All the source for this session is publically available at: https://github.com/SheepWorx/Training
• RSS Feed: http://learningaboutfudge.blogspot.com/feeds/posts/default?alt=rss
• Local Network: \\dmeyer-m\share\training\Code Like a Ninja
• Source was compiled using Visual Studio 2012
• http://www.gofpatterns.com/
Recommended