Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference to Design Patterns in ANSI C?

Can you point me to a reference of design patterns in Standard C (C89 or C99)? (Not C#, not C++.)

like image 607
Markus Schnell Avatar asked Jun 19 '09 14:06

Markus Schnell


People also ask

Are there any design patterns in C?

There are various patterns in the C language like star patterns, number patterns, and character patterns.

What is C pattern design?

Design patterns are solutions to software design problems you find again and again in real-world application development. Patterns are about reusable designs and interactions of objects. The 23 Gang of Four (GoF) patterns are generally considered the foundation for all other patterns.

What are the 3 types of patterns?

Three Types of Design Patterns (Behavioral, Creational, Structural) Distinguish between Behavioral, Creational, and Structural Design Patterns.


3 Answers

Take a look at Axel-Tobias Schreiner's ebook Object-Oriented Programming with ANSI-C. You'll have to handroll some aspects of some patterns but you'll be able to implement many of the simpler GoF ones.

like image 86
Rob Wells Avatar answered Oct 02 '22 10:10

Rob Wells


Design patterns should be language agnostic - unfortunately most of them assume an object oriented environment.

Struggling with C coming from Object Oriented land?

like image 34
Nick Van Brunt Avatar answered Oct 02 '22 10:10

Nick Van Brunt


Following from Nick's answer, I suggest that you learn how to implement cplusplus-like things using C (e.g., a C struct with a pointer to a table of function pointers, emulates a C++ class with virtual functions), which means understanding how C++ is implemented by the compiler. Once you've done this then you'll be able to read design patterns for C++ and implement them using C.

like image 25
ChrisW Avatar answered Oct 02 '22 09:10

ChrisW