University of Cincinnati logo and link  
CinJUG: Design Patterns, October 16, 2006
 
 

Closing Thoughts

UC ingot

This is a nice example, but does it work in real life?

  • Yes.  I've used it many times.

How did this example fit with the pattern descriptions?

They are a pretty close fit, with some liberties taken. 

  • The GoF book is language-neutral.  One of the shortcomings it identifies with the Factory Method is that the method has to have intimate knowledge of the subclasses that it is implementing.  But, by using Class.forName().newInstance(), we were able to abate that concern.
  • Many Abstract Factory and Factory Method examples have an actual abstract Factory class that is extended into concrete classes.  This is not always necessary, and it is not something I did - I combined these roles into one class, the MonthlyFactory.  But, MonthlyFactory can be extended.
  • Our example is farily simple, and only simulates calls to external classes.  A real command pattern might have Receiver objects that are called by the command objects.  These receivers could be web service calls, print service calls, database calls, etc.

How could I improve this example?

  • Consider ways to loosen the integration of File throughout the program.  Perhaps have the execute() method not use explicit parameters.
  • More classes and inheritance, less coupling.
  • Your thoughts?

What potential problems may exist with this design?

  • Proliferation of classes.
  • File-name dependencies.
  • Possibility of hacking by creating a new file type and new class to handle it.

Other Patterns

  • Singleton
  • Proxy
  • And many more!
Do you use patterns?
  • What patterns?  How do you use them?  What is your favorite?


 Cincinnati Java Users Group
Resource: http://www.patterndepot.com/put/8/Behavioral.html