4 ms·
I believe you describing at least one of two cases: 1. There are multiple methods on the object (not counting constructor) 2. There are arguments passed to the
by Laremere 6y ago
I believe you describing at least one of two cases:
1. There are multiple methods on the object (not counting constructor)
2. There are arguments passed to the methods.
Either of these cases are different from the provided example: The example will only ever compute a single value per object, always returning that value from a single method with no arguments (other than self).
- mehrdadn 6y agoNot necessarily. What I said can apply to even a class with with 1 method that takes no arguments... though you might often recognize it as a more sophisticated kind of iterator: class BFS(object): def __init__(self, origin): self.origin = origin; ... def next(self): ...
- twic 6y agoRight. I think the article is talking about one very specific case, which is apparently common amongst novice C++ programmers, where there is a single computation, whose only inputs come from the constructor, and which gets done in a method. There are plenty of cases where it makes sense to wrap a function in an object, but the point of the article is that this isn't one of them!