Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any "design patterns" in C? [closed]

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. ;-)

like image 673
onemasse Avatar asked Nov 06 '10 10:11

onemasse


People also ask

What is C pattern design?

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."

Is design pattern only for OOP?

Absolutely not. It doesn't have to be tied to object-orientation (OOP).

Are there more than 23 design patterns?

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.


1 Answers

My favorite is the "Patterns in C" series by Adam Tornhill:

  • First-Class ADT
  • State
  • Strategy
  • Observer
  • Reactor

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.

like image 84
coolaj86 Avatar answered Oct 06 '22 01:10

coolaj86