Reputation: 8461
I'm just getting into design patterns and what I'm reading is that the pattern is typically independent of language.
In programming we have OOP and non-OOP (is there a name for non-OOP?).
I've recently been playing with the template pattern and it seems to almost counter-intuitive for OOP. The fact it's just effectively a bunch of "Go To Methods" (reminding me of Pascal to a degree) seems some how 'against' how OOP wants to behave.
Does this mean that some patterns are better suited to languages (and I appreciate that having some thing not perfectly suited doesn't mean it's not suitable).
Upvotes: 1
Views: 93
Reputation: 14591
Patterns are independent of languages, but are often specific for a language family. There are patterns common to OO languages, some are common to functional languages, etc.
Let's take a visitor pattern as an example: it is popular in a subset of OO languages which don't support multiple dispatch (C++, Java, C# - short of dynamic
s). However, it is completely needless in languages where multiple dispatch is a language feature (Common Lisp, Clojure).
With regard to OOP vs non-OOP, there are multiple non-OOP paradigms: functional languages, procedural languages, etc. Many are really multiparadigm-languages, e.g. C++ - it provides features of OO, procedural and functional languages. On the other hand, many people don't consider it a real OO language, as types are not first-class objects in C++, and they are likely right.
Upvotes: 1
Reputation: 5578
The template pattern is actually a very good example of OOP when done properly because you can refer to a group of related objects by their abstract type, and operate on them in a similar fashion because they each implement the same "contract" of methods. That pattern is said to define algorithm/program structure, but in most basic cases, it's really just polymorphism.
You could argue that some patterns are better suited to other languages, but you can pretty much use any pattern in any language.
Upvotes: 2