Design patterns are useful for object oriented languages.
But how can a non-object-oriented language such as C make of use them?
7
To reinforce the answers already given, a quote from GOF Design Patterns book itself:
Our patterns assume Smalltalk/C++-level language features, and that choice determines what can and cannot be implemented easily. If we assumed procedural languages, we might have included design patterns called “Inheritance”, “Encapsulation” and “Polymorphism”.
While the design patterns described there are geared towards object-oriented software, and certainly object-oriented programming languages are a natural fit for it, the concepts they embody are language agnostic. What varies is the work overhead you would have to invest to implement the required OOP feature or a workaround for it.
4
From the wikipedia article on Software design patterns:
a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design
As you can see, there is no mention of object oriented programming here.
Design patterns apply to any computer language and sometimes are higher level (architectural patterns).
One example is for SQL – there is a even a book for SQL Design Patterns.
Design patterns are not limited to certain languages or language families. You could come up with design patterns for any language or paradigm.
If you are referring to the GOF patterns: Have a look at stdout
, stderr
and stdin
in C. That’s the strategy pattern which does not seem so OO after all.
BTW:
Object Oriented Programming is not language dependend. Some languages make it easier, some make it harder, but you can program “object oriented” in any universal (as in ‘not special purpose’ like e.g. SQL) language.
8