是否有任何“设计模式”?在C中?

编程入门 行业动态 更新时间:2024-10-09 21:24:48
本文介绍了是否有任何“设计模式”?在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 :

  • 一流的ADT
  • 状态
  • 策略
  • 观察员
  • 反应器
  • 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 )而不是C,除非您需要使用c。 Rust具有c的所有优点,包括速度和与c的二进制库兼容性,但是编译器处理了许多复杂性,以确保代码是内存安全的并且不包含数据竞争。它也是便携式的,具有用于执行常见任务的标准库,并且可以轻松地针对各种设计模式进行编程。

Update: I'd highly recommend using Rust (rust-lang) 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中?

本文发布于:2023-11-29 06:02:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1645547.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有任何   模式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!