Couple of Days back 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 (29 and Appendix A).
1) The ordinary way to extend a class hierarchy's behavior is to add methods that provide the behavior you need. It may happen, though, that the behavior you need is not consistent with the thrust of the existing object model. In other cases, the developer of a hierarchy may have little information about the behaviors that later developers will need.
2) If the developers who control the hierarchy code can't or won't change quickly enough to meet your needs, it may be impossible to extend the hierarchy's behavior without modifying the hierarchy's classes. But VISITOR lets a hierarchy developer build in support for the prospect that another developer may want to extend the behavior of the hierarchy. The intent of VISITOR is to let you define a new operation for a hierarchy without changing the hierarchy classes.
3) VISITOR is a controversial pattern. Some developers consistently avoid applying it; others defend its use and suggest ways to strengthen it, although these suggestions usually add complexity. The fact is that many design problems tend to accompany the VISITOR pattern.
4) The VISITOR pattern lets you define a new operation for a hierarchy without changing the hierarchy classes. The mechanics for VISITOR include defining an interface for visitors and adding accept() methods in the hierarchy that a visitor will call. The accept() methods dispatch their calls back to the visitor in a double-dispatching scheme. This scheme arranges for the execution of a visit() method that applies to the specific type of object from the hierarchy.
5) A visitor developer must be aware of some, if not all, of the subtleties in the design of the visited hierarchy. In particular, visitors need to beware of cycles that may occur in the visited object model. This type of difficulty leads some developers to eschew VISITOR, regularly applying alternatives instead. Using VISITOR should probably be a team decision that depends on your methodology and the specifics of your application.
6) Design patterns often make a design stronger. This is not a new idea, so it is no surprise that many design patterns are built into the Java class libraries. If you can spot the design pattern in a body of code you can grasp the design yourself and communicate it to others who understand design patterns. For example, if a developer understands the DECORATOR pattern, it is meaningful to explain that Java streams are decorators.
Tuesday, 20 January 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment