12 ms·
I don't think I agree with using objects as the public interface to an algorithm, especially if its primary purpose is to apply some transformation over the inp
by vore 7y ago
I don't think I agree with using objects as the public interface to an algorithm, especially if its primary purpose is to apply some transformation over the input (i.e. a natural fit for a function). The examples given have a bit of a two-phase initialization smell: initialize some internal state, then run the algorithm: steps that are never performed separately.
Objects as an algorithm internal state might be a better approach: the caller doesn't have to worry about the algorithm's internal state, they only need to call the external function entry point (and you'll destroy or otherwise forget the internal state at the end of the function, rather than putting the burden on the caller).
- edflsafoiewq 7y agoA good example is hashing hasher = Hasher(iv) hasher.hash(data) hasher.hash(data2) ... hash = hasher.finish() Compression/decompression is similar.