是否有任何“设计模式”?在C中? [英] Are there any "design patterns" in C?

查看:83
本文介绍了是否有任何“设计模式”?在C中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道设计模式通常与OO编程有关,但是您在编程C时是否经常使用某些模式?

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?

我不是对经典OO模式的简单翻译感兴趣,请不要提及Duff的设备。 ;-)

I'm not interested in simple translations of the classical OO patterns and please don't mention Duff's device. ;-)

推荐答案

我最喜欢的是 Adam Tornhill

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

总是将 goto 视为装饰图案的穷人工具。

Also: I always think of goto as a great poor man's tool for the decorator pattern.

更新 >:我强烈建议使用 Rust rust-lang.org )而不是C,除非您需要使用c。 Rust具有c的所有优点,包括速度和与c的二进制库兼容性,但是编译器处理了许多复杂性,以确保代码是内存安全的并且不包含数据竞争。它也是便携式的,具有用于执行常见任务的标准库,并且可以轻松地针对各种设计模式进行编程。

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.

这篇关于是否有任何“设计模式”?在C中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆