lundi 15 janvier 2018

Sharing a hashmaps and some other data structures among different classes

In a web application I want to execute some methods, that belong to different classes. Method calling will be done in a chain (1st method calls 2nd, 2nd calls 3rd... and so on). Each method is going to make some entries or updates in some hashmaps or other data structures. After all the methods are executed, I have to make some updates in my database.

As per my understanding, I have below options to achieve this:

  1. Keep passing the hashmaps, from one method to other. I think it's a bad approach.

  2. Keep those hashmaps in separate class. Create an object of that class and keep that object passing from one method to other and so on. This approach looks better than 1st to me but it still involves passing an object from one object to other leading to a tightly coupled design.

  3. Using static hashmaps (or hashtables) or static object of the seperate class made as in option 2. (This I think is worse approach because static variables will be shared aming different users).

Please help me in understanding the best approach.

Aucun commentaire:

Enregistrer un commentaire