GeeCON Prague 2014*
The moose likes OO, Patterns, UML and Refactoring and the fly likes What pattern should I use? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "What pattern should I use?" Watch "What pattern should I use?" New topic
Author

What pattern should I use?

Kurt Xu
Ranch Hand

Joined: Sep 29, 2009
Posts: 32
Hello all:
I'm writing an app to determine whether the execution result of struts action and bussiness object intercepted through intercepter of spring and struts is successful, the interface to do it is named 'SuccessChecker' , six default build-in checker implement classes have been developed, if those don't reach the requirement, you need to implement it on your own, below is part code of the factory class.



My confusion is there're many logic to select a proper concrete factory method , whose parameters are different from other's. In this case , do I still need write such factory? Is that right I don't use it and just create a implement class of SuccessChecker? But meanwhile I discovered java.util.Calendar is in a situation similar to mine. Calendar has method with different parameters to return a concrete Calendar implement class, but it's an abstract class that is extended by like GregorianCalendar. Is that suitable I mimic Calendar.
thanks.
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2265
    
    3

Howdy, Kurt!

My confusion is there're many logic to select a proper concrete factory method , whose parameters are different from other's. In this case , do I still need write such factory?


Well champ, it's sort of hard to say, but, since you are using Spring, have you considered using dependency injection? You can provide the class that implements the SuccessChecker in an XML file and arrange the objects there... this way, you wouldn't have to write the factory.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Kurt Xu
Ranch Hand

Joined: Sep 29, 2009
Posts: 32
Roberto Perillo wrote:Howdy, Kurt!

My confusion is there're many logic to select a proper concrete factory method , whose parameters are different from other's. In this case , do I still need write such factory?


Well champ, it's sort of hard to say, but, since you are using Spring, have you considered using dependency injection? You can provide the class that implements the SuccessChecker in an XML file and arrange the objects there... this way, you wouldn't have to write the factory.

The problem is the app first parse all information from a configuration xml file ,then create a proper SuccessChecker instance for every configuration , many configuration with different class of SuccessChecker requirement. I change the SuccessChecker to a abstract class like Calendar does, define multiple factory method, as following:


Every Functionality represents a piece of configuration ,requiring a SuccessChecker instance , my app is a framework to handle all kinds of request, no way to predefine a specific SuccessChekcer implement class in a framework.
thank Roberto
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2265
    
    3

Howdy, Kurt.

The problem is the app first parse all information from a configuration xml file


Champ, can you show us a sample of this configuration file of yours?
 
GeeCON Prague 2014
 
subject: What pattern should I use?