4 ms·
> Like the 'visitor pattern' -- does any pattern intro tell people that this exists only because Java and C++ have no multiple dispatch? It's not exactly a sec
by humanrebar 9y ago
> Like the 'visitor pattern' -- does any pattern intro tell people that this exists only because Java and C++ have no multiple dispatch?
It's not exactly a secret. The Double Dispatch wikipedia page has a visitor section: https://en.wikipedia.org/wiki/Double_dispatch#Visitor_pattern https://en.wikipedia.org/wiki/Double_dispatch#Visitor_patter...
> Java, the language without verbs
Right. But in the C++ standard library, they use a version of the factory pattern (see make_shared) to allow for some optimizations and nicer syntax.
Separating some construction options from the class definition itself allows for more separation of concerns with no real loss to encapsulation.
> I don't understand 'patterns'.
I mostly agree that patterns help you work around language limitations. Though having names for concepts is generally helpful to help move the state of the art forward. There are "sidecar", "proxy", and "broker" patterns in system design. If we didn't have those, we'd have to reinvent prose every time we were describing those maneuvers to our coworkers and (even harder) strangers in the industry.
- pcr0 9y agoVisitor pattern isn't just used to overcome language limitations. In Rails it's used to dynamically generate SQL statements for different databases.