3 ms·
”It’s impossible for a client to call the wrong function; there’s only one way of doing things. my_algorithm = MyAlgorithmClass() results = my_algorithm.ru
by Someone 7y ago
”It’s impossible for a client to call the wrong function; there’s only one way of doing things.
my_algorithm = MyAlgorithmClass()
results = my_algorithm.run()
“
Only one? That API opens the door for
my_algorithm = MyAlgorithmClass()
results = my_algorithm.run()
more_results = algorithm.run()
, which, hopefully, resets exactly the right amount of state to work just fine.
There’s also the ‘fun’ of sharing an ‘algorithm’ between threads. That will teach you that this ‘algorithm’ is more a set combining function arguments with function state, and a method that uses them to compute a result. Next, if you’re smart, you’ll separate the arguments from the state.
⇒ if you do something like this, use that builder pattern.