Yesterday i started reading Design Patterns Java™ Workbook By Steven John Metsker.
Nice book written by Steven John Metsker.
I wanted to share few quotations found the book from the next 2 chapters (5-6).
1) A composite is a group of objects in which some objects may contain others; thus, one object may represent groups, and another may represent an individual item, or leaf. When you model a composite, two powerful concepts emerge. One important modeling idea is to design groups so that they can contain either individual items or other groups. (A common error is to define groups so that they can contain only leaves.) A second powerful concept is to define common behaviors for individual objects and for compositions. You can bring these ideas together by
defining a common type for groups and items and by modeling groups as containing a collection of objects of this type. This fulfills the intent of the COMPOSITE pattern: COMPOSITE lets clients treat individual objects and compositions of objects uniformly.
2) COMPOSITE contains two powerful, related concepts. One concept is that a group can contain either individual items or other groups. Related to this concept is the idea that groups and individual items may share a common interface. These ideas come together in object modeling, whereby you can create an abstract class or a Java interface that defines the behaviors that are common to groups and to individual objects.
Modeling composites often leads to recursive definition of methods on composite nodes.When recursion is present, a danger exists of writing code that produces an infinite loop. To avoid such problems, you can take steps to guarantee that your composites are always trees.Alternatively, you can allow cycles to occur in a composite, but you have to modify your algorithms to watch for recursion. You can handle cycles in composites by maintaining a collection of observed nodes.
3) The Bridge Pattern focuses on the implementation of an abstraction. Design Patterns (Gamma et al. 1995) uses the word abstraction to refer to a class that relies on a set of abstract operations, where several implementations of the set of abstract operations are possible.
4) The ordinary way to implement an abstraction is to create a class hierarchy, with an abstract class at the top that defines the abstract operations; each subclass in the hierarchy provides a different implementation of the set of abstract operations. This approach becomes insufficient when you need to subclass the hierarchy for another reason. It can also happen that the abstract operations need to be defined and implemented in advance of abstractions that will use them.
You can create a bridge by moving the set of abstract operations to an interface, so that an abstraction will depend on an implementation of the interface. The intent of the BRIDGE pattern is to decouple an abstraction from the implementation of its abstract operations, so that the abstraction and its implementation can vary independently.
5) A Classic Example of Bridge: Drivers
A common use of BRIDGE occurs when an application uses a driver. A driver is an object that operates a computer system or an external device according to a well-specified interface.Applications that use drivers are abstractions: The effect of running the application depends on which driver is in place. Each driver is an instance of the ADAPTER pattern, providing the interface a client expects, using the services of a class with a different interface. An overall design that uses drivers is an instance of BRIDGE. The design separates application development from the development of the drivers that implement the abstract operations on which the applications rely.
6) An everyday example of applications using drivers to operate computer systems appears in database access. Database connectivity in Java usually depends on JDBC. ("JDBC" is a trademarked name, not an acronym.) A good resource that explains how to apply JDBC is JDBC Database Access with Java™ (Hamilton, Cattell, and Fisher 1997). In short, JDBC is an application programming interface (API) for executing structured query language (SQL) statements. Classes that implement the interface are JDBC drivers, and applications that rely on these drivers are abstractions that can work with any database for which a JDBC driver exists. The JDBC architecture decouples an abstraction from its implementation so that the two can vary independently—an excellent example of BRIDGE.
7) A common example of BRIDGE occurs in drivers. An application that uses a driver is an abstraction—the choice of driver determines what happens when the application runs. The interface between applications and drivers lets you vary either side independently. You can create new applications that use the drivers without changing the drivers. You can also add new drivers without changing existing applications. That is the intent of BRIDGE.
You may encounter abstractions that are not decoupled from their implementation but rather are arranged as an abstract class whose concrete subclasses provide various implementations.In such a case, you can apply BRIDGE if you want to factor the hierarchy along another line.Moving the implementations out lets each implementation become a new class that implements a standard interface. This lets you add new subclasses to the abstraction,regardless of which implementation of the interface you will use. This move also lets you add new implementations of the interface without affecting the abstraction hierarchy. The BRIDGE pattern decouples an abstraction from its implementation so that the two can vary independently.
Glossary ( starting D pg: 386)
DOUBLE DISPATCH
A design in which a class B object dispatches a request to a class A object, and the class A object immediately dispatches a request back to the class B object, with additional information about the class A object's type.
ENTERPRISE JAVABEANS
A specification of an n-tier, component-based architecture.
GRAMMAR
A set of composition rules.
HOOK
A provision that a developer places in his or her code to give other developers a chance to insert code at a specific spot in a procedure.
IMMUTABLE
Unchangeable; specifically, an object with values that cannot change.
IMPLEMENTATION
The Java statements that make up the bodies of a class's methods.
INTERFACE
The collection of methods and fields that a class permits objects of other classes to access. Also, a Java interface that defines the methods that an implementing class must provide.
INTERPRETER
An object composed from a composition hierarchy in which each class represents a composition rule that determines how the class implements, or interprets, an operation that occurs throughout the hierarchy.
JAVA DEVELOPMENT KIT
A collection of software that includes the Java class libraries, a compiler, and other supporting tools; usually refers specifically to kits available at java.sun.com.
JDBC
An application programming interface for executing SQL statements. JDBC is a trademarked name, not an acronym.
Monday, 29 December 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment