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 6861503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:32:35+00:00 2026-05-27T02:32:35+00:00

My problem is to create a class which would let to use an object

  • 0

My problem is to create a class which would let to use an object (settings container or simply container) safely. I have more than 10 methods where I have to repeat the same actions: save the the container’s state, change the state, do some job, restore the state, return results. Example:

public List<String> childKeys() {
    //saving state (repeated many time in other methods)
    final String clientGroup = clientSettings.group();
    //changing state  (repeated many time in other methods)
    clientSettings.endAllGroups();
    clientSettings.beginGroup(currentGroup);
    //doing job (exclusive for each method)
    final List<String> childKeys = clientSettings.childKeys();
    //restoring state  (repeated many time in other methods)
    clientSettings.endAllGroups();
    clientSettings.beginGroup(clientGroup);

    return childKeys;
}

I need doing this to prevent a user changing system settings and want to avoid writing the same code many times.
Do you see any way to redesign the code so the methods calls could be prepared and cleaned up automatically?

  • 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-05-27T02:32:36+00:00Added an answer on May 27, 2026 at 2:32 am

    If I understand you well, you want to make sure a certain code is called before and/or after a certain set of methods?

    Have you considered AOP? That would be a nice way to add the same code to a bunch of method calls without polluting your code with superclasses / extra-calls all over the place.

    Spring-AOP is a nice implementation of it, which uses AspectJ under the hood. Have a look.

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

Sidebar

Related Questions

I would like to have some suggestions for the following problem: Let's say you
I need to create class Dog and PurebredDog extending Dog. Problem is that Dog
I'm having a problem with curl_multi_* , I want to create a class /
Here is my problem. I have created a pretty heavy readonly class making many
I have a peculiar problem. I created a normal Objective C class called SampleTable.
I have a problem with the Create View in the SimpleRepository example in Subsonic
I want to use object instances as modules/functors, more or less as shown below:
I have to register an object in a container upon its creation. Without smart
I've been wondering why would I use Exceptions in my PHP. Let's take a
Let's consider this scenario: a freshly create windows form application in which I created

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.