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

  • Home
  • SEARCH
  • 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 8485755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:44:14+00:00 2026-06-10T20:44:14+00:00

I have an application which stores many many variables as attributes on the session.

  • 0

I have an application which stores many many variables as attributes on the session. Each time I need one, I have to remember what the attribute name was exactly, and cast it back to its type to use it.

I was considering using a single object to contain all these variables, and call it something like “SessionManager” so that I only need to remember one attribute name and casting will not fail.

I wondered if this was a pattern or if there is a similar or better existing pattern?

  • 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-10T20:44:16+00:00Added an answer on June 10, 2026 at 8:44 pm

    Sounds like you need some kind of cache for your session.

    You can’t help but know the attribute name. However you could skip the casting part with a specialized method for each object type (ideally you wouldn’t have many diffrent types other than primitives)

    Since you mention Java EE i’d go for a stateless bean that implements the following operations
    defined in an interface:

    String getString(string fieldName);
    int getInt(string fieldName);
    DateTime getDateTime(fieldName);
    ...
    object getObject(fieldName); // for special scenarios
    void setInt(string fieldName, int value);
    void setString(String fieldnName, String value);
    ...
    

    In the bean implementation i would add for extra flexibility:

    Define two classes that implement the former interface (besides the bean class). One could store and read the values from memory and the other could do so from the database. And add an strategy patter that lets you select the class you want to use (again since you use Java EE this could be an Application Server variable)

    Summing it up:

    Create an interface that exposes the types you need (to avoid casting)
    Implement said interface in an EJB
    Implement said interface in as many classes as different data stores you want to use
    Implement a simple strategy pattern (no need for a dedicated class, an switch statement in the EJB would do) that selects the appropiate class.
    Call the EJB client from your code.

    Hope that helps

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

Sidebar

Related Questions

I have an application which stores data to the persistent store by setting the
I have a linked list, which stores groups of settings for my application: typedef
I have a PHP based web application which is currently only using one webserver
I have an application that stores data in database. I need search functionality to
I have an application which takes data from a file and stores it for
I'm designing a database application which stores simple contact information (First/Last Name etc.) and
I have some entities with relationships: component name=Store persistent=true { property name=Products fieldtype=one-to-many cfc=Product;
I have two tables in my application. The first one, Sections, stores content for
I have a database in my application in which I store something like a
I have an ASP.net application which returns a binary PDF file (stored from the

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.