2 ms·
> In both cases the old `factorial` works and the enhanced one fails. Does class computer_enhanced = object inherit computer method prev x =
by ernst_klim 7y ago
> In both cases the old `factorial` works and the enhanced one fails.
Does
class computer_enhanced = object
inherit computer
method prev x = x
end
tells you that factorial definition changed and that it's dependent on prev? No.
Does
fact(x, fun x -> x)
tells you that this function's behavior depends on `fun x -> x`? Yes.
- protomolecule 7y ago`factorial` definition hasn't changed, what changed is its implicit parameter. The word 'inherit' tells you that all methods of the `computer` class are potentially affected, including `factorial` unless you can see in `pred`'s contract that it affects only `factorial`. If you call your class `computer` and put a bunch of unrelated methods in it, then, yes, you are in big trouble, but you can abuse anything - you can create a data structure with hundreds of data members and make all your 'pure' functions take and return it. To sum it up: I see your point, but I don't think that it's a fatal flow of OOP, it's just a way to abuse it.