Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

EJBHome

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,
I have been trying to figure out which pattern EJBHome interface will fall into. When I did a search on the forum, I came across the following thread which argues the EJBHome as a Factory Method pattern. I wonder how the EJBHome qualifies as a Factory Method pattern.
Click here
A detailed explanation is greatly appreciated
Thambi
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest definition of a Factory is a class or interface that hides the creation of objects of another class or other classes.
EJBHome hides the creation of EJB objects, and hence it is a Factory.
If the Factory creates a family of related objects, it's an Abstract Factory.
If the Factory creates a complex object incrementally, it's a Builder.
If the Factory creates the object using inheritance, it's using a Factory Method.
If the Factory creates the object using delegation or copying, it's a Prototype.
Just because the EJBHome is not any of the above, does not mean it is not a Factory.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nilesh, just wondering where did you come up with those descriptions?
 
Nilesh Pereira
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reading my post now, they sound like I'm quoting fixed rules, but they're not. After all, you can implement an AbstractFactory using a FactoryMethod, or a Builder or a Prototype. All the creational patterns are infact quite inter-related. Rather, they're more like guidelines for identifying those patterns, extracted from GoF.
As far as I remember, the intent of the FactoryMethod in GoF was something like this:
"Define an interface for creating an object, but let subclasses decide which class to instantiate."
Based on this intent, I don't see how EJBHome qualifies as a FactoryMethod. Or am I missing something?
Rather I would argue that it is a Factory that uses aTemplateMethod. Does that make it a FactoryMethod?
 
Thambi Rajah
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Nilesh Pereira for your prompt replies. I was clear from your first reply, but I got little confused with your second reply.


"Define an interface for creating an object, but let subclasses decide which class to instantiate."
Based on this intent, I don't see how EJBHome qualifies as a FactoryMethod. Or am I missing something?


Assume EJBHome qualifies to be a FactoryMethod pattern. In this case, is EJBHome a Creator class/interface? What is the ConcreteCreator class in this case? I understand that the Product interface is EJBObject. What would be the ConcreteProduct class ?
The Creator, ConcreteCreator, Product , ConcreteProduct are the conventions used by GoF book on pg 108.
Thanks in advance
Thambi
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say that if the EJBHome interface is GOF's Creator, then the ConcreteCreator would be the implementation class generated by the EJB container.
[ April 25, 2003: Message edited by: Lasse Koskela ]
 
Nilesh Pereira
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lasse, could you please explain how the EJBHome satisifes the intent of the GoF FactoryMethod pattern. Thanks, I would appreciate it.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Nilesh Pereira:
Lasse, could you please explain how the EJBHome satisifes the intent of the GoF FactoryMethod pattern. Thanks, I would appreciate it.


I am not feeling 100% sure about this but my initial "feeling" was that the specification of EJBHome defines how (as in method signature) the objects are created but does not implement any strategy.
The EJB container's implementation of the EJBHome interface acts as the "ConcreteCreator" defining one particular way to construct the object. E.g. "I am the ConcreteCreator and I say we construct the EJBObject by doing this and that and instantiating that class over there."
As I said, it's not too sound but I think it's close.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a family can contain one single member, EJBHome is AbstractFactory.
 
Thambi Rajah
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Lasse Koskela for your input.


Originally posted by Lasse Koskela:
I'd say that if the EJBHome interface is GOF's Creator, then the ConcreteCreator would be the implementation class generated by the EJB container.


Your argument makes me believe that EJBHome is a Factory Method pattern. I can see the classes
Creator, ConcreteCreator and Product fit into Factory Method pattern. I wonder what the ConcreteProduct class would be? Would it be the Bean class implemented by the developer or would it be a class generated by the EJB container?
Thanks in advance
Thambi
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Thambi Rajah:
I can see the classes Creator, ConcreteCreator and Product fit into Factory Method pattern. I wonder what the ConcreteProduct class would be? Would it be the Bean class implemented by the developer or would it be a class generated by the EJB container?


I'd say the generated proxy/whatever would be the ConcreteProduct. But the bean implementation class obviously provides an essential part of its functionality.
 
Thambi Rajah
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,
Thanks for all of your input.
Can we summarize our discussion in the following way to confirm that the EJBHome is a
Factory Method pattern? Please feel free to correct me if I am wrong.
Summary
-------
EJBHome qualifies to be a Factory Method pattern. As we follow the conventions in GoF Book, the follwing classes/interfaces take the corresponding roles:
class/interface GoF Convention(pg 108)
--------------- ----------------------
EJBHome(interface) Creator
MyBean_HomeImpl(class) ConcreteCreator
EJBObject(interface) Product
MyBean_Impl(class) ConcreteProduct
where MyBean_HomeImpl, MyBean_Impl classes are arbitrary names, and are generated by EJBContainer. These names vary from one vendor to another.
When a Client invokes create() method using EJBHome reference, home:

the corresponding factory method create() in MyBean_HomeImpl is invoked, and MyBean_HomeImpl
instantiates an instance of MyBean_Impl class. Therefore, remote_ref points to the instance of
MyBean_Impl.
Having brought EJBHome, EJBObject, MyBean_HomeImpl, MyBean_Impl interfaces/classes into the Structure, how do we bring the Bean class(class implemented by the Developer)into the Struture? The proxy pattern comes in this
regard in the following way:
class/interface GoF Convention(pg 209)
--------------- ----------------------
EJBObject(interface) Subject
MyBean_Impl(class) Proxy
MyBean(Bean class) RealSubject
When a Client invokes a business method, getFirstName(), using remote reference, remote_ref:

MyBean_Impl invokes the method implementation of getFirstName() in MyBean class.
Thank You
Thambi
 
Thambi Rajah
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, last posting did not work well. I repeat..
Hello Ranchers,
Thanks for all of your input.
Can we summarize our discussion in the following way to confirm that the EJBHome is a
Factory Method pattern? Please feel free to correct me if I am wrong.
Summary
EJBHome qualifies to be a Factory Method pattern. As we follow the conventions in GoF Book,
the follwing classes/interfaces take the corresponding roles:
class/interface --------> GoF Convention(pg 108)
EJBHome(interface) --------> Creator
MyBean_HomeImpl(class) -------->ConcreteCreator
EJBObject(interface) --------> Product
MyBean_Impl(class) --------> ConcreteProduct
where MyBean_HomeImpl, MyBean_Impl classes are arbitrary names, and are generated by EJBContainer.
These names vary from one vendor to another.
When a Client invokes create() method using EJBHome reference, home:

the corresponding factory method create() in MyBean_HomeImpl is invoked, and MyBean_HomeImpl
instantiates an instance of MyBean_Impl class. Therefore, remote_ref points to the instance of
MyBean_Impl.
Having brought EJBHome, EJBObject, MyBean_HomeImpl, MyBean_Impl interfaces/classes into the Structure,
how do we bring the Bean class(class implemented by the Developer)into the Struture? The proxy pattern comes in this
regard in the following way:
class/interface --------> GoF Convention(pg 209)
EJBObject(interface)--------> Subject
MyBean_Impl(class) --------> Proxy
MyBean(Bean class) --------> RealSubject
When a Client invokes a business method, getFirstName(), using remote reference, remote_ref:

MyBean_Impl invokes the method implementation of getFirstName() in MyBean class
Thank You
Thambi
 
Ranch Hand
Posts: 8943
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by yi zhu:
As a family can contain one single member, EJBHome is AbstractFactory.



So are all examples of Factory method pattern also examples for AbstarctFactory pattern ?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic