Bitcoin Forum
April 26, 2024, 07:24:53 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: What is the best programming design pattern to use for my case?  (Read 447 times)
tyz (OP)
Legendary
*
Offline Offline

Activity: 3360
Merit: 1530



View Profile
August 21, 2016, 02:38:25 PM
 #1

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?
The trust scores you see are subjective; they will change depending on who you have in your trust list.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
criptix
Legendary
*
Offline Offline

Activity: 2464
Merit: 1145


View Profile
August 21, 2016, 08:36:38 PM
 #2

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

                     █████
                    ██████
                   ██████
                  ██████
                 ██████
                ██████
               ██████
              ██████
             ██████
            ██████
           ██████
          ██████
         ██████
        ██████    ██████████████████▄
       ██████     ███████████████████
      ██████                   █████
     ██████                   █████
    ██████                   █████
   ██████                   █████
  ██████
 ███████████████████████████████████
██████████████████████████████████████
 ████████████████████████████████████

                      █████
                     ██████
                    ██████
                   ██████
                  ██████
                 ████████████████████
                 ▀██████████████████▀
.LATTICE - A New Paradigm of Decentralized Finance.

 

                   ▄▄████
              ▄▄████████▌
         ▄▄█████████▀███
    ▄▄██████████▀▀ ▄███▌
▄████████████▀▀  ▄█████
▀▀▀███████▀   ▄███████▌
      ██    ▄█████████
       █  ▄██████████▌
       █  ███████████
       █ ██▀ ▀██████▌
       ██▀     ▀████
                 ▀█▌
 

             ▄████▄▄   ▄
█▄          ██████████▀▄
███        ███████████▀
▐████▄     ██████████▌
▄▄██████▄▄▄▄█████████▌
▀████████████████████
  ▀█████████████████
  ▄▄███████████████
   ▀█████████████▀
    ▄▄█████████▀
▀▀██████████▀
    ▀▀▀▀▀
tyz (OP)
Legendary
*
Offline Offline

Activity: 3360
Merit: 1530



View Profile
August 26, 2016, 04:38:45 PM
 #3

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.
tyz (OP)
Legendary
*
Offline Offline

Activity: 3360
Merit: 1530



View Profile
September 09, 2016, 06:18:13 PM
 #4

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.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!