mercredi 25 novembre 2020

What design pattern should I use to combine three data sources that communicate in a chain?

Specific Questions:

  1. What is the best design pattern or strategy for this particular problem?
  2. How can I prevent potential cascading effects & re-writing the code?

Details:

I am developing a program in which I have three data sources (A, B, C). In order to grab data from B, I need information from A. In order to pull data from C, I need information from B.

Current Approach:

Description:

I used four classes. A mediator class that handles the passing of data from A, B, & C. Then, a separate class for A, B, & C that handles extracting, formatting, sub-setting, etc.

Process Flow:

  1. Inside the mediator class I instantiate classes A, B, & C.
  2. I run a function inside the mediator class called create_A_files().
  3. The data from A that B needs is then passed as an argument to B's create_B_files(A_necessary_data) function.
  4. Finally, the same is done from B to C through a create_C_files(B_necessary_data) function.

Problems with Current Approach:

I am fighting cascading effects. Any changes I make in A propagate and cause errors & bugs in B & C. Therefore, I have to go back and rewrite B & C to accommodate the changes from A.

Thank you in advance for your help! Narnia649

Aucun commentaire:

Enregistrer un commentaire