design - Strategy pattern in domain model -


I'm experiencing an example where the pattern of the strategy should be used in a domain model. I have a user class that shows users of the system Each user can receive a request when using the system. After processing the request, some processing logic is possible:

  • Automatically remove requests
  • Received requests Notify the user about
  • etc. .

    In this case, it seems that the nature of the strategy is favorable. I have an interface called RequestReceivedPolicy with many sections implementing this interface (i.e. per process logic one class). The user class places a reference on an example of a class related to the selected policy.

    This item seems right on the side. My question is related to the stubborn side, in my case, there is a relational database. A user selects a policy through a management interface. I want to continue this option so that the next time the user is logged in, this information will be saved. I had thought about continuing the example of the User class, but I do not think this is the right way, because this example is more about the argument than the data.

    Thanks Edit:

      Public Request Received {Public Boolean Process Request (); } Public ignoreRequestPolicy applies RequestReceivedPolicy {Public Boolean Process Request () {// Ignore Argument}} Public CustomRequestPolicy {Private int someData1; Private string someData2; Public Boolean Process Revest () {// Custom Logic which uses data 1 and some data 2}}    

    The location of the policy choice depends on the location of how that policy is passed or configured in your user class, and you are not actually expanding it Have done

    If, for example, your user class is something like this:

      class user {// policy ctor during public user Passed the responsibility responsible for creating (object other agents, RequestReceived Policy policy) {}}   

    ... then user that < External priority must be maintained by code> user .

    Similarly, if the user object is simple, it is the requestReceivedPolicy context:

      class user {public user (object otherrg) {} public zero set policy (RequestReceivedPolicy policy) ) {_currPolicy = policy; } Public request received policy getPolicy () {Return _currPolicy; }}   

    ... and user class no way again to set your policy object, you public user (user user)

       

    object other request, request recipient policyholder policy provider) {} Public Zero Some Stimuli (Object Criteria, ...) {_currPolicy = _policyProvider.getPolicy (Criteria); }}

    ... or this ...

      class user {public user (object other advertisement) {} public zero something styled (object criteria , ..) {_currPolicy = PolicyProvider.getInstance (). GetPolicy; }}   

    ... then the user object should continue to select it so that it can pull the policy object when it is created later. In this case, it is the "criteria" that needs to be retained, and if it was an request received policy there was an additional method to return that criterion, it could be helpful :

      Requested Revival Policy Config Policy Conflict = _currPolicy.getConfiguration ();   

    The RequestReceivedPolicyConfig object should be opaque to user objects, but there may be simple dictionaries that support continuity, and then the user Without knowing more, you can pass in perseverance layer. When pulling it firmly from the layer, it is used to restore RequestReceivedPolicy using the provider. At a minimum, each RequestReceivedPolicyConfig object will have a class identity of RequestReceivedPolicy .

    It is possible to have a hybrid, where the policy has been pushed through set / receipt, but the user object also through a few of the above, such as PolicyProvider.getInstance (), to a new policy Can pull GetPolicy you still keep the user object externally or firmly based on the requested refresh policy config .

Comments

Popular posts from this blog

python - Assemble mpeg file unable to play in mediaplayer -

c# - crystal report failed -

mongodb - CakePHP paginator ignoring order, but only for certain values -