Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8553241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:36:25+00:00 2026-06-11T14:36:25+00:00

What’s the common approach (or design pattern) for this problem : I have a

  • 0

What’s the common approach (or design pattern) for this “problem” :

  1. I have a lot of controllers in a web application (struts actions in
    JAVA to be precise).
  2. Some controllers sets variables in the user’s session.
  3. Some controllers use those variables, remove them, modify them,
    etc…

It’s messy because it’s hard to know who set what, in what condition, where it changes…

Should I use the Mediator pattern :
http://en.wikipedia.org/wiki/Mediator_pattern

Or the Facade pattern like this (example in c#) :
http://foxsys.blogspot.ca/2007/01/session-facade-aspnet-c.html

Or something else?


Example of the workflow of a variable and how it can be messy :

  1. The user choses a preferred product. The ChooseProductController sets the id of the preferred product in session

  2. The user creates an account : The CreateAccountController checks if a preferred product is in session. If it’s the case, it creates the account in DB with this id

  3. The user is logged in. The LoginController checks if a preferred product is in session. If it’s different from the one in DB when the account was created, the view needs to display a message to ask the use to choose the preferred product.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:36:26+00:00Added an answer on June 11, 2026 at 2:36 pm

    First advice: use the session as seldomly as possible. Try to only use it for things that have a lifetime identical to the lifetime of the session, and that can’t be retrieved from the database easily or fast enough.

    Second advice: don’t use the session directly. Encapsulate the access to the session in one or a few dedicated class(es) (like you would do for a database, except the session is an in-memory database). Instead of doing

    Product preferredProduct = (Product) session.getAttribute("preferredProduct");
    

    , do something like

    SessionStore.getInstance(session).getPreferredProduct();
    

    This is more readable, much less error-prone, and allows finding easily in all the codebase where the preferred product is get or set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.