I know that design patterns is generally something that's connected to OO programming, but do you have some pattern you often use when you program C?
I'm not interested in simple translations of the classical OO patterns and please don't mention Duff's device. ;-)
Design Patterns in the object-oriented world is a reusable solution to common software design problems that occur repeatedly in real-world application development. It is a template or description of how to solve problems that can be used in many situations. "A pattern is a recurring solution to a problem in a context."
Absolutely not. It doesn't have to be tied to object-orientation (OOP).
There are 23 official patterns from the book Design Patterns - Elements of Reusable Object-Oriented Software, which is considered one of the most influential books on object-oriented theory and software development.
My favorite is the "Patterns in C" series by Adam Tornhill:
Also: I always think of goto
as a great poor man's tool for the decorator pattern.
Update: I'd highly recommend using Rust (rust-lang.org) rather than C except where you are required to use c. Rust has all of the benefits of c, including speed and binary library compatibility with c, but the compiler handles much of the complexity to ensure that the code is memory safe and does not contain data races. It's also portable, has a standard library for common tasks, and much easier to program with for various design patterns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With