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
Solved

Is this factory  pattern ?

Posted on 2006-11-21
7
322 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
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
more than one jdk and one jre 1 50
runtime exception 2 41
Bot application - advice 3 37
restrict decimal places for double datatype 10 19
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

789 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