[翻译] Effective C++, 3rd Edition, Chapter 4. Designs(设计)和 Declarations(声明)
2006-01-22 21:30
513 查看
Chapter 4. Designs(设计)和 Declarations(声明)
作者:Scott Meyers
译者:fatalerror99 (iTePub's Nirvana)
发布:http://blog.csdn.net/fatalerror99/
软件设计——使软件能做你想让它做的事情的途径——典型情况下,从一个相当概括的想法开始,但是最终它们会变得详细,详细到足以进行具体的 interfaces(接口)的开发。这些 interfaces(接口)很可能在随后被转化为 C++ declarations(声明)。在本章,我们触及设计和声明优良的 C++ interfaces(接口)的问题。我们以或许是设计各种 interfaces(接口)的最重要的指导方针开始:它们应该易于正确使用,而难以错误使用。这也为许多从范围广阔的主题中选择的更特殊的指导方针设置了舞台,包括 correctness(正确性),efficiency(效率),encapsulation(封装),maintainability(可维护性),extensibility(可扩展性),以及 conformance to convention(顺应惯例)。
后面的素材并不是你需要知道的关于好的 interface(接口)设计的全部内容,而是采集了一些最重要的注意事项,一些最容易发生的错误的警告,并为 class(类),function(函数)和 template(模板)的设计者经常遇到问题给出了解决方案。
本章包括以下内容,点击打开:
Item 18: Make interfaces easy to use correctly and hard to use incorrectly
Item 19: Treat class design as type design
Item 20: Prefer pass-by-reference-to-const to pass-by-value
Item 21: Don't try to return a reference when you must return an object
Item 22: Declare data members private
Item 23: Prefer non-member non-friend functions to member functions
Item 24: Declare non-member functions when type conversions should apply to all parameters
Item 25: Consider support for a non-throwing swap
作者:Scott Meyers
译者:fatalerror99 (iTePub's Nirvana)
发布:http://blog.csdn.net/fatalerror99/
软件设计——使软件能做你想让它做的事情的途径——典型情况下,从一个相当概括的想法开始,但是最终它们会变得详细,详细到足以进行具体的 interfaces(接口)的开发。这些 interfaces(接口)很可能在随后被转化为 C++ declarations(声明)。在本章,我们触及设计和声明优良的 C++ interfaces(接口)的问题。我们以或许是设计各种 interfaces(接口)的最重要的指导方针开始:它们应该易于正确使用,而难以错误使用。这也为许多从范围广阔的主题中选择的更特殊的指导方针设置了舞台,包括 correctness(正确性),efficiency(效率),encapsulation(封装),maintainability(可维护性),extensibility(可扩展性),以及 conformance to convention(顺应惯例)。
后面的素材并不是你需要知道的关于好的 interface(接口)设计的全部内容,而是采集了一些最重要的注意事项,一些最容易发生的错误的警告,并为 class(类),function(函数)和 template(模板)的设计者经常遇到问题给出了解决方案。
本章包括以下内容,点击打开:
Item 18: Make interfaces easy to use correctly and hard to use incorrectly
Item 19: Treat class design as type design
Item 20: Prefer pass-by-reference-to-const to pass-by-value
Item 21: Don't try to return a reference when you must return an object
Item 22: Declare data members private
Item 23: Prefer non-member non-friend functions to member functions
Item 24: Declare non-member functions when type conversions should apply to all parameters
Item 25: Consider support for a non-throwing swap
相关文章推荐
- [翻译] Effective C++, 3rd Edition, Item 7: 在 polymorphic base classes(多态基类)中将 destructors(析构函数)声明为 virtual(虚拟)
- [翻译] Effective C++, 3rd Edition, Chapter 2. Constructors(构造函数),Destructors(析构函数)与 Assignment Operators(赋值运算符)
- [翻译] Effective C++, 3rd Edition, Item 22: 将 data members(数据成员)声明为 private
- [翻译] Effective C++, 3rd Edition, Chapter 6. Inheritance(继承)和 Object-Oriented Design(面向对象设计)
- [翻译] Effective C++, 3rd Edition, Chapter 5. 实现
- [翻译] Effective C++, 3rd Edition, Chapter 1. 习惯于 C++
- [翻译] Effective C++, 3rd Edition, Chapter 3. Resource Management(资源管理)
- [翻译] Effective C++, 3rd Edition, Item 19: 视 class design(类设计)为 type design(类型设计)
- [翻译] Effective C++, 3rd Edition, Chapter 7. Templates(模板)和 Generic Programming(泛型编程)
- [翻译] Effective C++, 3rd Edition, Item 24: 当希望将 type conversions(类型转换)应用于所有 parameters(参数)时,请声明为 non-member functions(非成员函数)
- [翻译] Effective C++, 3rd Edition, Item 9: 绝不要在 construction(构造)或 destruction(析构)期间调用 virtual functions(虚拟函数)
- [翻译] Effective C++, 3rd Edition, Item 28: 避免返回 object 内部构件的 "handles"(“句柄”)
- [翻译] Effective C++, 3rd Edition, Item 29: 争取 exception-safe code(异常安全代码)(上)
- [翻译] Effective C++, 3rd Edition, Item 30: 了解 inlining(内联化)的来龙去脉(下)
- [翻译] Effective C++, 3rd Edition, Item 44: 从 templates(模板)中分离出 parameter-independent(参数无关)的代码(上)
- [翻译] Effective C++, 3rd Edition, Item 47: 为类型信息使用 traits classes(特征类)(下)
- [翻译] Effective C++, 3rd Edition, Item 39: 谨慎使用 private inheritance(私有继承)(上)
- [翻译] Effective C++, 3rd Edition, Item 2: 用 consts, enums 和 inlines 取代 #defines
- [翻译] Effective C++, 3rd Edition, Item 20: 用 pass-by-reference-to-const(传给 const 引用)取代 pass-by-value(传值)(上)
- [翻译] Effective C++, 3rd Edition, Item 20: 用 pass-by-reference-to-const(传 const 引用)取代 pass-by-value(传值)(下)