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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:26:57+00:00 2026-06-14T15:26:57+00:00

I am encountering an example where the strategy pattern in a domain model should

  • 0

I am encountering an example where the strategy pattern in a domain model should be used. I have a User class representing users of the system. Each user may receive requests while using the system. Upon reception of a request, some processing logics are possible:

  • Automatically remove the requests
  • Notify the user about the received request
  • etc…

In this case, it seems that the strategy pattern is adapted. I have an interface called RequestReceivedPolicy with multiple classes that implement this interface (i.e. one class per processing logic). The User class holds a reference on one instance of the class corresponding to the selected policy.

This seems right on the object side. My question concerns the persistence side which, in my case, is a relational database. A user selects a policy through the a management interface. I want to persist this choice so that next time the user login, this information is saved. I thought about persisting the instance hold by the User class but I don’t think it’s the right way, since this instance is more about logic than data.

Thanks


EDIT:

public RequestReceivedPolicy {
    public boolean processRequest(); 
}

public IgnoreRequestPolicy implements RequestReceivedPolicy {
    public boolean processRequest(){
       //ignore logic
    } 
}

public CustomRequestPolicy {
    private int someData1;
    private String someData2;

    public boolean processRequest(){
       //custom logic that uses someData1 and someData2
    } 
}
  • 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-14T15:26:58+00:00Added an answer on June 14, 2026 at 3:26 pm

    The location of the policy choice persistance depends on where/how that policy gets passed in or configured into your User class, and you didn’t really ellaborate that.

    If, for example, your User class has something like this:

    class User
    {
       // policy is passed in during ctor
       public User(object otherArgs, RequestReceivedPolicy policy)
       {
       }
    }
    

    …then the class responsible for creating the User would likely have to maintain that preference external to User.

    Similarly, if the User object simple holds the RequestReceivedPolicy reference like this:

    class User
    {
       public User(object otherArgs)
       {
       }
    
       public void setPolicy(RequestReceivedPolicy policy)
       {
          _currPolicy = policy;       
       }
    
       public RequestReceivedPolicy getPolicy()
       {
          return _currPolicy;       
       }
    
    }
    

    …and the User class has no way to set its own Policy object then, again, you have to rely on an external entity to persist the policy choice.

    If instead the policy selection is “pulled” into the User class like this:

    class User
    {
       public User(object otherArgs, RequestReceivedPolicyProvider policyProvider)
       {
       }
    
       public void someStimulii(object criteria, ...)
       {
          _currPolicy = _policyProvider.getPolicy(criteria);
       }
    
    }
    

    …or this…

    class User
    {
       public User(object otherArgs)
       {
       }
    
       public void someStimulii(object criteria, ...)
       {
          _currPolicy = PolicyProvider.getInstance().getPolicy(criteria);
       }
    
    }
    

    …then the User object should persist its selection so that it can pull that policy object when it is recreated/constructed again later. In this case, it is the “criteria” that would need to be persisted, and it might be helpful if the RequestReceivedPolicy had an additional method to return that criteria:

    RequestReceivedPolicyConfig policyConfig =  _currPolicy.getConfiguration();  
    

    The RequestReceivedPolicyConfig object should be opaque to the User object, but internally perhaps be simple dictionary that supports persistance. Then the User can pass it to the persistence layer without knowing much about it. When pulling it from the persistence layer, it is used to reinstall the RequestReceivedPolicy using the provider. At a minumum, each RequestReceivedPolicyConfig object would contain the class identity of the RequestReceivedPolicy.

    It is possible to have a hybrid, where the Policy is pushed via set/get but the User object can also pull in a new policy via something like the above PolicyProvider.getInstance().getPolicy(criteria) then you still allow the User object to take advantage of the RequestReceivedPolicyConfig based approach or keep persistence external.

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

Sidebar

Related Questions

We have some users which are using lower-CPU powered machines and they're encountering slow
Example here: http://jsfiddle.net/KyW6c/2/ I have an ordered list. Each list item is a project
recently I have been encountering problems with exposing events from .NET to COM. I
I'm encountering a situation where I'm using pattern matching for determining the visibility property
I'm creating a system that turns a small script into a dll. I'm encountering
I have an application, which uses some 3rd party libraries, for example Tesseract library.
Consider the following example: as part of configuration for my program the user supplies
I'm encountering a problem whereby i have fields in a form that has variable
Here's a problem I'm encountering: Example Data df <- data.frame(1,2,3,4,5,6,7,8) df <- rbind(df,df,df,df) What
I'm encountering following problem with the twitter bootstrap framework and jQuery: I have 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.