• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

What pattern solves this?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's hard to tell from your rather abstract problem description, but you might want to take a look at the Null Object pattern.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
blacksmith
Posts: 1332
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic