This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes Decorator pattern, caching Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Decorator pattern, caching" Watch "Decorator pattern, caching" New topic
Author

Decorator pattern, caching

Sean Sullivan
Ranch Hand

Joined: Sep 09, 2001
Posts: 427
I am looking for articles or books that describe if/how to apply
the decorator pattern for the purposes of caching.
william kane
Ranch Hand

Joined: Nov 21, 2000
Posts: 260
Originally posted by Sean Sullivan:
I am looking for articles or books that describe if/how to apply
the decorator pattern for the purposes of caching.

Decorator pattern for caching??? For all that i know decorator is a pattern that allows you to add a subclass that will have a functionality applicable to all other subclasses thereby reducing the number of classes in hierarchy.
I wonder how it can be used for caching?Can you let know the reason for your choice?


Help me!Help you!!!
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
The idea was probably to "decorate" the existing class by introducing a cache check before calling the super class' getExpensiveInformation() method.
For example:


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
william kane
Ranch Hand

Joined: Nov 21, 2000
Posts: 260
Originally posted by Lasse Koskela:
The idea was probably to "decorate" the existing class by introducing a cache check before calling the super class' getExpensiveInformation() method.
For example:

hi lasse,
Is this what you meant by decorating for cache???

If yes, we are not using decorator pattern for caching right???
If no, please clarify.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
I should've named "MyCachedObject" as "MyDecoratedObject". That's what I meant.
I realize some resources say that subclassing is not an implementation of the Decorator pattern. In that sense, composition would be a more appropriate way to implement the decorator. However, in order to do this transparently we'd need an interface to implement (or to use with a dynamic proxy).
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

http://www.onjava.com/lpt/a/4361
The example shows how caching can be acheived using Filters.


Groovy
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Pradeep Bhat:
http://www.onjava.com/lpt/a/4361
The example shows how caching can be acheived using Filters.

That's a great article, Pradeep, but not really helping in implementing an object-level cache.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Originally posted by Lasse Koskela:

That's a great article, Pradeep, but not really helping in implementing an object-level cache.


Lasse,
Have you read the Caching section of the article
http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnaspp/html/aspnet-aspnet-j2ee-struts.asp
ASP .NET provides object-level caching. I feel that J2EE also needs to come up with some caching standard. What is you opinion Lasse?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
I hadn't read that article. Now I have read the Caching section of it
Yes, we need a standard caching method in J2EE. There is JSR-107, but it has been inactive for quite a while. Fortunately, there has been some changes in the expert group that could breathe new life into the JSR effort (Cameron Purdy of Tangosol was made the spec lead, Bela Ban from JavaGroups joined the expert group).
There are already a couple of open-source cache implementations such as OSCache, Java Object Cache, and JCache.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Decorator pattern, caching