|
|
|
|
|
by extension
5804 days ago
|
|
Imagine I have a system that generates a series of graphs based on a changing complex number. I could use a round-robin approach of constantly calling a set of functions, passing in a new complex number each time. This would work, but it’s incredibly clunky and doesn’t scale well. Alternatively, I could create a sub-class of ComplexNumber that uses a callback to expose its fields to just the main controlling class. I then use dependency injection to give all the graph drawers access to a reference to that value. The graph drawers can then run independently (say in different threads) and only the controlling class gets to change the value contained by that reference. This is a far neater. more robust and more scalable solution. So, the neat, robust, scalable solution is to subclass his immutable value class to make it mutable and then inject it into code expecting the immutable class and change it behind their backs? Step away from the compiler... |
|