sekhar
sekhar

Reputation: 700

which Design Pattern best suits for this scenario

I have a scenario in which, there i have a class(fallback.java) in this it has some string variables(popup,thumbnail,RealTime,....) these variables are getting initialized from a network call. I have 3 objects from 3 different class which are capable enough to store the values in these variables. These variables can be increased and liable objects are already inplace to incorporate these variables. Getting the data from variables and setting to objects happens at regular intervals.

Could you please suggest me best design pattern to suit this scenario..

Thanks, sekhar.

Upvotes: 0

Views: 342

Answers (2)

bennyl
bennyl

Reputation: 2956

It sounds like a strategy pattern to me (if I understand you correctly)

http://en.wikipedia.org/wiki/Strategy_pattern

EDIT:

for example:

class Fallback {
   Strategy strategy;
   String value;

   void operate(){
        strategy.operate(this);
   }

   enum Strategy {
       popup {
           public void operate(Fallback f){ /* Do something */ }
       },

       thumbnail {
           public void operate(Fallback f){ /* Do something */ }
       },

       realtime {
           public void operate(Fallback f){ /* Do something */ }
       };

       public abstract void operate(Fallback f);

   }
}

Upvotes: 1

Joni
Joni

Reputation: 111389

Design patterns help you when you are designing a system. From the description it sounds like you already have a design: a class with some string variables that get initialized from a network call etc. If you want to apply patterns you'll have to step back and see if any can help you meet the system requirements; retrofitting a design to look like a pattern provides no value.

Upvotes: 1

Related Questions