-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OOP: 以类和对象作为组织代码的单元以及它的三大特性 #37
Comments
继承 Inheritance: 如果多个类有一些相同的属性和方法,就可以讲这些相同的部分抽取到一个父类中,让子类继承父类,避免在子类中重复书写相同的代码
为了实现继承特性,编程语言需要提供特殊的语法机制,例如 java 使用 Using
|
多态 Polymorphism: 编译阶段调用父类,运行阶段调用子类替换 (override) 父类的版本我们知道封装、继承特性都需要编程语言提供特殊的语法机制来实现,多态特性也是如此。
|
抽象类和接口存在的意义封装不稳定的实现细节,暴露稳定的接口。上游系统面向下游系统提供的接口编程,不依赖不稳定的实现细节,而依赖稳定的接口。这样当下游系统实现细节发生变化的时候,上游系统的代码也基本不需要改动。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
封装 Encapsulation: 信息隐藏和数据访问保护
封装特性需要编程语言提供特殊的语法机制来实现(
public
、private
关键字)。The text was updated successfully, but these errors were encountered: