Bitcoin Forum

Other => Off-topic => Topic started by: tyz on August 21, 2016, 02:38:25 PM



Title: What is the best programming design pattern to use for my case?
Post by: tyz on August 21, 2016, 02:38:25 PM
I am looking for an appropriate design pattern to use for my case. Hope someone can point me to the best one.

I want to retrieve a web service that gives me information about TransactionTypeA and TransactionTypeB.

My current approach is the following:

I have a main class, a controller class and two model classes (one for each transaction type). Model classes differ in design (different amount of variables). Main class calls a method in controller class, for instance getTransactionTypeA that calls the web service, handles the json response and maps it to TransactionTypeA model class. The method returns a map of TransactionTypeA instance(s) (the web service could respond 1 to n transactions of a type with one call). Now, the main class iterates through the map in order to get the information. So far so good.

The problem is, the main class needs to know the model class of each transaction type (either TransactionTypeA or TransactionTypeB). I want to prevent this. I want that the main class only knows one overall instance which handles all the model classes. For example type TransactionType.

Any suggestions?


Title: Re: What is the best programming design pattern to use for my case?
Post by: criptix on August 21, 2016, 08:36:38 PM
You can code a loop in the main class that checks the transaction type and calls the respective model class.


Title: Re: What is the best programming design pattern to use for my case?
Post by: tyz on August 26, 2016, 04:38:45 PM
Thanks, I implemented a similar procedure but it is not really a well-designed programming approach. Therefore I removed it again.
That's why I am looking for a appropriate design pattern.

You can code a loop in the main class that checks the transaction type and calls the respective model class.


Title: Re: What is the best programming design pattern to use for my case?
Post by: tyz on September 09, 2016, 06:18:13 PM
I am still facing the problem. I have not found a good option yet. Any more suggestions for an appropriate design pattern?

I thought about the proxy pattern but it does not really fit to my case.