3 ms·
I've heard the quote about design patterns making up for the lack of features in a language. I've always been a little confused by it. Can you give me a good ex
by 3minus1 10y ago
I've heard the quote about design patterns making up for the lack of features in a language. I've always been a little confused by it. Can you give me a good example of a language feature that removes the need for a design pattern?
- thristian 10y agoIn Java, you'll sometimes see people handing around instances of nearly (or entirely) empty classes with a single method, for use as callbacks. In languages with first-class functions, you can just hand around function pointers directly, you don't need to dress them up with classes. In C, you'll sometimes see people make a struct containing only a collection of function pointers, and different parts of the code will produce instances of the struct with the function pointers populated differently. In languages with built-in polymorphism, this isn't necessary.
- lmm 10y agoA language-level match feature replaces many use cases of the visitor pattern. Typeclasses often remove the need for facades. First-class constructors (e.g. static virtual methods) remove the need for factories.