Solved

Is this factory  pattern ?

Posted on 2006-11-21
7
318 Views
Last Modified: 2013-11-24
Dear experts

I have a scenario where I have this code in Action class
OrderInfoDelegate orderInfoDelegate = (OrderInfoDelegate) DelegateFactory .getInstance().getDelegate("OrderInfo");

Where “OrderInfoDelegate”  is an interface which has this method
public interface OrderInfoDelegate
{
      public ControllingOrderVO saveOrderInfo(ControllingOrderVO conVO);

}

And the actual implementation is in another class called LocalDelegateOrderInfo which goes like :

public class LocalDelegateOrderInfo extends BaseDelegate implements OrderInfoDelegate
{

private OrderInfoLocal local;
private OrderInfoLocalHome home;

public LocalDelegateOrderInfo(String jndiServiceHomeName) {
            try {
                  home =
                        (OrderInfoLocalHome) ServiceLocator.getInstance().getLocalHome(
                              jndiServiceHomeName);
                  local = home.create();
            } catch (ServiceLocatorException ex) {
                  ex.printStackTrace();
            } catch (CreateException ex) {
                  ex.printStackTrace();
            }
      }      

      public ControllingOrderVO saveOrderInfo(ControllingOrderVO conVO) {

            //ControllingOrderVO coVO = null;
                  try {
                        conVO = (ControllingOrderVO) local.saveOrderInfo(conVO);
                  } catch (EJBException ejbExp) {
                        throw logExceptionFromEJB(ejbExp, FFMLoggingLevels.DEBUG);
                  }
                  return conVO;
            }



}
++++++++++++++++++++++++++++

From the above code is it right to say:

1. OrderInfoDelegate interface is like a factory method pattern which has the factory method

public ControllingOrderVO saveOrderInfo(ControllingOrderVO conVO);

According to Factory method pattern, a subclass instantiates the object.
2. So is “LocalDelegateOrderInfo”  the subclass and what object is it instantiating (if it is indeed factory pattern)


any Sugessions appreciated

Thanks
J
0
Comment
Question by:jaggernat
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:reach2piyush
Comment Utility
>> 1. OrderInfoDelegate interface is like a factory method pattern ...
OrderInfoDelegate seems like implementing a business method, where as a Factory class should only be having derived classes Instantiation code.

Although, the following line

>>OrderInfoDelegate orderInfoDelegate = (OrderInfoDelegate) DelegateFactory .getInstance().getDelegate("OrderInfo");

Here DelegateFactory looks like following factory pattern to create an instance of the Delegate class

>>2. So is “LocalDelegateOrderInfo”  the subclass and what object is it instantiating
This again is not Factory Implementation, but is a created instance by factory pattern (DelegateFactory)
0
 
LVL 10

Author Comment

by:jaggernat
Comment Utility
DelegateFactory  is actually returning a "delegate"  by using singleton design pattern.
0
 
LVL 10

Author Comment

by:jaggernat
Comment Utility
>>>> Factory class should only be having derived classes Instantiation code.

meaning Factoy class should always have something like    "new ConcreteClass()"   .true?

>>>
home =  (OrderInfoLocalHome) ServiceLocator.getInstance().getLocalHome(jndiServiceHomeName);
               local = home.create();

so does the above code mean "instantiation"?

thanks
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 8

Expert Comment

by:reach2piyush
Comment Utility
>>>
Factoy class should always have something like    "new ConcreteClass()"   .true?

Yeah, Factory class should just have if - else / switch-case constructs along with new ConcreteClass()

>>
so does the above code mean "instantiation"?

The Factory is more like a Java pattern & may not very well fit into many J2EE scenarios, As here the code is for getting a remote reference rather than instantiation, this may sort of exhibit ServiceLocator J2EE pattern ( again same as your naming convention explains..)  
0
 
LVL 10

Author Comment

by:jaggernat
Comment Utility
yea, i see what you are saying.

so you think factory pattern doesnt appear in J2EE scenario at all?

0
 
LVL 8

Accepted Solution

by:
reach2piyush earned 500 total points
Comment Utility
>> you think factory pattern doesnt appear in J2EE scenario at all

will not say "at all", for instance EJB Home Interfaces acts as a factory pattern to create instances of the EJB Object, as both are on the Server side & calling create will actually create an EJBObject (Entity beans record gets inserted)

but yes if we are trying to relate remote behaviour  or distributed programmming, the  factory pattern may not fit in..
0
 
LVL 10

Author Comment

by:jaggernat
Comment Utility
ok thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now