Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am writing a tool which runs several processes. These processes exchange information via message queue. It uses a config file for basic setting and writes to a log. So i pass a queue, a log object and the config down the structure of my program.

SomeClass(log, config, queue)
-> SomeClassLevel2(log, config, queue)
--> SomeClassLevel3(log, config, queue)
--> AnotherClass(log, config)
---> SomeClassLevel4(log, config)

So basicaly every class gets passed the same stuff and i have lines like this:

self.static_cluster_definition  = StaticClusterDefinition(self.log, self.config)
self.dynamic_cluster_definition = DynamicClusterDefinition(self.log, self.config)
self.logic_cluster_definition   = LogicClusterInformation(self.log, self.config)
self.host_definition            = HostDefinition(self.log, self.config)
self.shutdown_vm                = ShutdownVM(self.log, self.config)
self.vm_server_list             = VMServerList(self.log, self.config)
self.vm_index                   = VMIndex(self.log, self.config)

Now i want to provide statistics, which have to be gathered from all over the place. So i have to introduce another object, which is passed down.
One day i would have to pass like 30 objects down the whole code structure.

Is there a better way to do this?

question from:https://stackoverflow.com/questions/65936992/how-to-spread-information-objects-throughout-a-program

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
122 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...