Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • You said that keeping the state variables shared among class functions is fine. Let's for a second not create any dispatcher. These state variables are set and reset by class functions. There are no public getters and setters as we don't want other classes to get these variables. I think unit testing in this case would be difficult. Commented Mar 18, 2020 at 10:23
  • @NavjotSingh: A dispatcher would be appropriate for stuff like this; it wouldn't be surprising if a lack of a dispatcher would enable undue complexity in, e.g., unit tests. To be clear: the sharing of a mutable entity isn't problematic, but having scattered logics interacting with it could be. Commented Mar 18, 2020 at 10:31
  • Yes, scattered logic makes the code ugly and hard to read. Although I have to still wrap my head around this dispatcher as well. Commented Mar 18, 2020 at 10:32
  • @NavjotSingh: Just to check: are you familiar with multi-threaded programming and issues like race conditions? For example, do you understand the issue asked about in this question? Commented Mar 18, 2020 at 10:43
  • to be honest I asked the question in a general sense giving an example which involved DateTime but there can be other examples as well, like the one for logging which I gave in my question. Yes, I'm familiar with multi-threaded programming but my main aim was to look for a better design. Commented Mar 19, 2020 at 8:09