Comment by zahlman
5 hours ago
Really the fundamental problem is that Java teaches the class as the fundamental unit of abstraction, rather than the function. (It goes so far as to not even have functions that exist independently of a class; even "static" functions must have a class to serve as their namespace.) It is class-oriented programming, not object-oriented programming. When you are really oriented towards objects, naturally you will want functions to be first-class objects. That way you can actually compose them in all the usual ways that objects are composed, instead of being limited to composing them at call time (by sequentially calling them).
When functions are first-class objects, so much of the GoF book just dissipates into the ether. You don't have a "Command pattern", you just have a function that you pass as an argument. You don't have a "Factory pattern", you just have a function that you call to create an instance of some other thing. (And you don't even think about whether your "factory" is "abstract".) And so on and so forth. There is value in naming what you're doing, but that kind of formalism is an architectural smell — a warning that what you're doing could be more obvious, to the point where you don't notice doing it for long enough to think of a name.
No comments yet
Contribute on Hacker News ↗