设计原则,最佳实践和设计模式为C(或一般程序编程)? [英] Design Principles, Best Practices and Design Patterns for C (or Procedural Programming in general)?

查看:146
本文介绍了设计原则,最佳实践和设计模式为C(或一般程序编程)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存在任何已知的设计原则,最佳实践和设计模式,同时设计一个C项目,一个可以遵循?或有用的设计原则,在一般程序​​(必要)编程?

Are there any known design principles, best-practices and design patterns that one can follow while designing a C project? Or useful design principles for procedural (imperative) programming in general?

(我是'面向对象的一代的孩子,要设计的第一次大型C项目)

(I'm child of the 'object-oriented generation' and have to design a large C project for the first time)

推荐答案

信息隐藏 - 由尔格的信奉(软件基础)。

Information hiding - as espoused by Parnas (Software Fundamentals).

报头和知名度的精细化管理:

Careful management of headers and visibility:


  • 中,可以从外界被隐藏应是源文件的一切;只有记录的外部接口予以曝光。

  • 被暴露在头声明的一切。

  • 这头被用来在需要的功能(并在它被定义)。

  • 标题是自包含的 - 当你需要它,你使用它,你不用发愁什么其他的头我也有包括因为头保证了它的工作方式,包括任何需要使它工作。

  • 标题是自保护 - 。因此,如果它被包含多次不要紧

  • Everything in a source file that can be hidden from the outside world should be; only the documented external interface should be exposed.
  • Everything that is exposed is declared in a header.
  • That header is used where the functionality is needed (and where it is defined).
  • The header is self-contained - when you need it, you use it, and you don't have to fret about 'what other headers do I also have to include' because the header ensures it works by including anything it needs to make it work.
  • The header is self-protected - so it does not matter if it is included multiple times.

#ifndef HEADER_H_INCLUDED
#define HEADER_H_INCLUDED
...rest of header contents, including other #include lines if necessary
#endif /* HEADER_H_INCLUDED */


  • 设计的函数集在对象(一般结构)的工作 - 并使用这些功能,而不是周围的结构在code,它在使用它的内脏戳。把它看成是自我强加的封装。

  • Design sets of functions to work on 'objects' (usually structures) - and use those functions rather than poking around the innards of the structure in the code that is using it. Think of it as self-imposed encapsulation.

    这篇关于设计原则,最佳实践和设计模式为C(或一般程序编程)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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