Bjarne Stroustrup大师谈

artima网站对在Bjarne Stroustrup在2003进行了专访,摘录了一些有感触的内容。

1.        有责任维护类的不变性的函数应该成为类的接口The functions that are taking any responsibility for maintaining the invariant should be in the class

 

2.        如果一个类的成员可以是任何的值,那么他成为类的意义就不大(也许可以成为一个结构structIf every data can have any value, then it doesn't make much sense to have a class.

 

3.        如果一个类有太多的setget函数,那么意味着它不应该是一个类(也许可以成为一个结构struct. I particularly dislike classes with a lot of get and set functions.

 

4.        辅助函数并不是利用类继承的合法理由 I've seen the Date problem solved by having a base class Date with some operations on it and the data protected, with utility functions provided by deriving a new class and adding the utility functions

 

多接口和单实现

5.         有的时候多继承,纯粹是为了方便;你可以使用聚合,但是不方便。

 

6.        给问题建模尽可能的直接和简单,但是不能更简单了。you try to model the problem as directly and simply as possible, but no simpler

 

7.        资源获取就是初始化的含义就是把资源的获取和释放放在构造函数和析构函数中,So "resource acquisition is initialization" is a consequence of the view of hiding allocation and deallocation by dealing with it in constructors and destructors of classes

 

8.         设计工具不会给你更多的帮助,你应该开发一个小的系统,然后逐渐的升级为一个大的系统。Design tools don't give you much feedback, so therefore I tend towards the view that you should build a smaller system and grow it into a bigger one.

 

9.        建造函数库,然后使用它们I think people should mentally separate programming into building libraries and using them.

 

10.    丑陋的操作应该使用丑陋的语法An ugly operation should have an ugly syntactic form

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值