Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Is this factory  pattern ?

Posted on 2006-11-21
7
Medium Priority
?
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:reach2piyush
ID: 18005440
>> 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
ID: 18005447
DelegateFactory  is actually returning a "delegate"  by using singleton design pattern.
0
 
LVL 10

Author Comment

by:jaggernat
ID: 18005459
>>>> 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:reach2piyush
ID: 18005608
>>>
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
ID: 18005800
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 2000 total points
ID: 18006075
>> 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
ID: 18007980
ok thanks
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

661 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