Solved

Is this factory  pattern ?

Posted on 2006-11-21
7
324 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
check java version using powershell 13 472
Running JavaFX on JDeveloper 12C 1 116
passing enum to a method 4 52
Java List 4 76
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.
Suggested Courses

751 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