Solved

Is this factory  pattern ?

Posted on 2006-11-21
7
326 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

615 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