1.6 面向对象的核心特征

封装Encapsulation:

is the process of hiding the implementation details of an object隐藏了对象的实现细节

the internal state in usually not accessible by other objects内部的状态不为其他对象所访问

the only access to manipulate the object data is through its interface 对象的数据只能通过接口访问

继承 Inheritance

the basic principle is simple 

多态 Polymorphic

when one class inherits from another ,then polymorphism allows a subclass to stand in for the superclass 当一个类从另一个类继承而来,多态使得子类可以代替父类

the sender of astimulus doesn't need to know the recdiver's class 消息发送方不需要知道消息接收方属于哪个子类

different receivers can interpret the message in their own way 同一类族的接收者可以按照自己的方式处理消息

使用指向父类的指针或引用,能够调用子类的对象这是设计模式的核心基础

扫描二维码关注公众号,回复: 4991503 查看本文章

聚合/组合 Aggregation/composition整体和部分的关系

inheritance继承,飞机是一种交通工具,is a

aggregation聚合 交通工具中由飞机 has a

聚合 a contains b,b contains c ,a contains c 传递性

组合整体控制部分的生命 树死了,树叶也死了

聚合飞机毁了,其他交通工具还在

接口/实现 interface/implementation

抽象 Abstraction

h

猜你喜欢

转载自www.cnblogs.com/mayZhou/p/10293967.html
1.6