Get your CodeRanch badge!*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Decorator Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Decorator Pattern" Watch "Decorator Pattern" New topic
Author

Decorator Pattern

JigaR Parekh
Ranch Hand

Joined: May 23, 2005
Posts: 112
Hi,

How javax.ejb.EJBObject is example of decorator Pattern?

Regards,
Jigar
[ May 12, 2008: Message edited by: JigaR Parekh ]
Vishal Matere
Ranch Hand

Joined: Jan 22, 2008
Posts: 81
I doubt about it.
javax.ejb.EJBObject is example of proxy pattern


SCJP <br />SCWCD <br />SCBCD <br />SCEA-1
JigaR Parekh
Ranch Hand

Joined: May 23, 2005
Posts: 112
this has been mention as example in book SCEA study guide by Paul R. Allen, Joseph J. Bambara

yes i agree that it should be example of Proxy.

Regards,
Jigar
wang andrew
Ranch Hand

Joined: May 12, 2008
Posts: 31
It should be decorator pattern. App server wraps the original bean method and adds other functionalities like transaction, security...
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
How can only an interface be an example of a design pattern?

I think only one pattern can be represented by only one class, that is Singleton pattern.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
John Hall
Greenhorn

Joined: Apr 06, 2008
Posts: 15
EJBObject is there both in decorator and proxy pattern.

excerpt from Paul Allen's SCEA book.

"Java EE Technology Feature The Java EE technology feature associated with
the Proxy pattern is javax.ejb.EJBObject (EJB remote reference) in a structural sense.
Actually the �stub� object in the client�s address space provides the proxy."


Still not clear why it's an decorator pattern. Any DP expert???
JigaR Parekh
Ranch Hand

Joined: May 23, 2005
Posts: 112
Originally posted by wang andrew:
It should be decorator pattern. App server wraps the original bean method and adds other functionalities like transaction, security...


Then EJBHome should also be example of decorator pattern but it is not see below question which has been asked in Mark Cade book.

Which pattern is used by the Home Interface of an EJB?
A. Proxy
B. Decorator
C. Mediator
D. Factory

The correct answer is D.
Ajay Singh Rathore
Ranch Hand

Joined: Mar 27, 2008
Posts: 64
Originally posted by JigaR Parekh:


Then EJBHome should also be example of decorator pattern but it is not see below question which has been asked in Mark Cade book.

Which pattern is used by the Home Interface of an EJB?
A. Proxy
B. Decorator
C. Mediator
D. Factory

The correct answer is D.



EJBHome is not based on decorator pattern because in case of EJBHome container is not adding any services to the actual purpose of the home object. The actual purpose of EJBHome is to act as a singleton factory for producing EJBObjects

EJBObject- This is a bit complex. You can say that when remote client accesses the EJBHome through jndi look up he gets a stub or a proxy object based on the proxy pattern which talks to the skeleton on the server side which in turn talks to the EJBObject implementation provided by server which wraps the actual bean instance. For each client method invocation, the EJB Object decorates the bean instance with services like security, transaction before invoking the actual methood on the bean instance.
JigaR Parekh
Ranch Hand

Joined: May 23, 2005
Posts: 112
EJBObject as decorator pattern i have seen so many places but not able to understand why? Any body who has better understanding about design Patterns
Ajay Singh Rathore
Ranch Hand

Joined: Mar 27, 2008
Posts: 64
JigaR,

I am surprised to see you still have doubts about it after my explanation.
Try understanding a simple decorator pattern example[HF design pattern] and then link it with EJBObject

Here EJBObject is a decorator object which knows how to talk to the bean instance and also doing this it accomplishes some other functionality(security, transaction).

For eg Consider java IO classes like BufferedInputStream is a decorator which decorates the InputStream.
JigaR Parekh
Ranch Hand

Joined: May 23, 2005
Posts: 112
yes i am still confused but not as why EJBObject is example of decorator but as why EJBHome is not example of decorator.
i might trying little hard to understand.

As you have correctly said that container will wrap services like Security and transaction around EJBObject will provide dynamically exatra resposibilty with actual bean.

this can be true to EJBHome also because EJBHome also gets wrapped with additional functionality like security.

I hope you can understand my doubt.

Regards,
Jigar
Ajay Singh Rathore
Ranch Hand

Joined: Mar 27, 2008
Posts: 64
Originally posted by JigaR Parekh:
yes i am still confused but not as why EJBObject is example of decorator but as why EJBHome is not example of decorator.
i might trying little hard to understand.

As you have correctly said that container will wrap services like Security and transaction around EJBObject will provide dynamically exatra resposibilty with actual bean.

this can be true to EJBHome also because EJBHome also gets wrapped with additional functionality like security.

I hope you can understand my doubt.

Regards,
Jigar


JigaR i doubt that weather server implementation of EJBHome provides any sort of security services.
If you think logically the purpose of EJBHome in case of session bean is only to create EJBObjects, and the question of security or transaction only comes in picture when client calls the bean methods on the EJBObject stub not the EJBHome stub.

So the moral of the story is that EJBHome is a factory and EJBObject is a decorator.

Regards,
Ajay Singh Rathore

SCJP , SCDJWS
Pedro Erencia
Ranch Hand

Joined: Apr 03, 2008
Posts: 70
I'd say: EJBObject, as a Stub, is a Proxy. As an EJB, is a Decorator.
[ May 29, 2008: Message edited by: Pedro Erencia ]
Sri Kor
Ranch Hand

Joined: Sep 03, 2001
Posts: 35
Hi Ajay,

You explained it in the best possible way. I agree with you on everything you said.

Thanks


SCJP2<br /> <br /><a href="http://www.primeguru.com" target="_blank" rel="nofollow">Share Your Personal Experiences</a>
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
There are a few major differences between the Proxy and Decorator object-oriented design patterns. In the lastest version of the Enterprise Javabeans API, the EJBObject class is no longer used.

When talking about the older versions of the EJB API, EJBObject was an implementation of the Decorator pattern. Code of the EJBObject added additionall functionality to the actual bean class. It "decorated" the bean class with additional functionality. EJBObject did not serve as a Proxy and was never used as a "stand-in" for the actual bean class.

Either way, the EJBObject was deprecated.
Rodrigo Cunha
Ranch Hand

Joined: Mar 19, 2008
Posts: 44
Originally posted by James Clark:
There are a few major differences between the Proxy and Decorator object-oriented design patterns. In the lastest version of the Enterprise Javabeans API, the EJBObject class is no longer used.

When talking about the older versions of the EJB API, EJBObject was an implementation of the Decorator pattern. Code of the EJBObject added additionall functionality to the actual bean class. It "decorated" the bean class with additional functionality. EJBObject did not serve as a Proxy and was never used as a "stand-in" for the actual bean class.

Either way, the EJBObject was deprecated.


I am going to emerge this topic from the ashes to ask a question for those who already took the new SCEA 5 exam. Should I expected to see assumptions regarding old artifacts such as EJBObject in questions (about patterns or any subject) at the new SCEA5 exam?


Rodrigo Cunha<br />SCJP, SCWCD, SCEA5(I)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Decorator Pattern
 
Similar Threads
Is this a design pattern?
Decorator Pattern ??
List of Patterns used in Java SE
Decorator design pattern
decorator pattern from HFDP