Structural_Patterns_6

Structural_Patterns_6 - Structural Patterns Structural...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Structural Patterns Structural Patterns • The structural patterns are the common ways that different types of objects can be organized to work with each other. Structural Patterns • Adapter – describes how an object can have a client that expects it to implement a particular interface, even though it does not implement the interface. • Iterator – describes how an object can access the contents of a collection of objects without knowing the structure or class of the collection. Structural Patterns • Bridge – describes how to manage parallel hierarchies of abstractions and implementations. • Façade – describes how to hide the complexity of using a group of related objects behind a single object. • Flyweight – describes how to avoid multiple instances of an object consuming memory by sharing instances that contain common values. • Dynamic Linkage – Describes how to dynamically add classes to a program at runtime. Structural Patterns • Virtual Proxy – Describes how to postpone the creation of objects in a way that is transparent to their clients. • Decorator – Describes how to dynamically augment or modify the behavior of existing objects. • Cache Management – Describes how to avoid creating similar objects multiple times by reusing the object that was previously created. Adapter Patterns • An Adapter class – implements an interface known to its clients and – provides access to an instance of a class not know to its clients. • An adapter object provides the functionality promised by an interface without having to assume what class is being used to implement that interface.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Adapter Patterns • You want to use a class that calls a method through an interface, but you want to use it with a class that does not implement the interface. • Modifying the class to implement the interface is not an option either because – You do not have the source code for the class. – The class is a general-purpose class and it would be inappropriate for it to implement an interface for a specialized purpose. • You want to dynamically determine which of another object’s methods an object calls without the object having knowledge of the other object’s class. Simple Copy Filter Copy Filter Adapter Adapter Pattern Code Example 1 class Frame1_jMenuHelpAbout_ActionAdapter implements ActionListener { Frame1 adaptee; Frame1_jMenuHelpAbout_ActionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jMenuHelpAbout_actionPerformed(e); } } Code Example 2 class Frame1_contentPane_mouseAdapter extends java.awt.event.MouseAdapter { Frame1 adaptee; Frame1_contentPane_mouseAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void mousePressed(MouseEvent e) { adaptee.contentPane_mousePressed(e); } public void mouseReleased(MouseEvent e) { adaptee.contentPane_mouseReleased(e); }
Background image of page 2
3 Iterator • A class needs access to the contents of a collection without becoming dependent on
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

Structural_Patterns_6 - Structural Patterns Structural...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online