很多教材广为流传的一句话,面向对象的本质是封装,继承,多态
参考object-oriented的创造者,图灵奖获得者Alan Kay对面向对象的解释
按照他的理解 messaging才是oo的首要特征,也就是“发送和处理消息的”,一个世界在他眼里就是很多个节点在互相发送和处理消息
比如A节点给B节点发消息 = A这个节点的object调用了B这个节点的object的某个method
同一条消息可以被多个节点处理,但是这些节点对同一条消息的处理结果和方式不相同,这个有点像多态
两个节点之间无法互相看到对方的内部状态也无法做更改,能做的只有接收和发送消息,这个有点像封装
在他的描述里也看不到继承这个词,对于继承是否是面向对象的本质,个人更倾向于理解成这是一个实现方式
Alan Kay原话:I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages (so messaging came at the very beginning – it took a while to see how to do messaging in a programming language efficiently enough to be useful).
…
OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP.