aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes What pattern solves this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "What pattern solves this?" Watch "What pattern solves this?" New topic
Author

What pattern solves this?

T Ray
Greenhorn

Joined: Jul 11, 2004
Posts: 6
Hello All,
I have an application where a certain object is used by many JSPs or Servlets. While using objects, its hard to keep track of the status of that object. Because of that, JSPs and Servlets end up using that objects when its state is not valid to be referenced and throws expception. is there any Pattern that might help keep track the state of objects? do i necessarily use a Pattern in situation like this? I would appreciate if you could provide some suggestion in regards to how to deal with this situation. Thanks.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
It's hard to tell from your rather abstract problem description, but you might want to take a look at the Null Object pattern.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Since you mentioned state, look at state pattern. The state-sensitive object can change its behavior based on its state. A method might return computed results in StateA, throw an exception in StateB and return a default value in StateC.

Ilja's null object suggestion might be very similar if you're getting the state-sensitive object from a factory ... you might get back a fully functional object or one that just returns harmless values.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Warren Dew
blacksmith
Ranch Hand

Joined: Mar 04, 2004
Posts: 1332
    
    2
Not a pattern, but there is something that solves this: use of the "object creation is initialization" paradigm. If you always have the constructor or factory function return an object that is already initialized and ready to use, and all of the object's public methods continue to leave it in a state that's ready to use, that solves your problem.

In formal terms, object creation should set up the object's invariant, and all public methods should continue to maintain the invariant.
Vladas Razas
Ranch Hand

Joined: Dec 02, 2003
Posts: 385
I have this book "Professional SCWCD Certification". There is "Designing and Developing Thread-Safe Servlets" chapter. I suspect that your application may suffer from these kind of problems. In short there might be synchronization problems.
 
 
subject: What pattern solves this?