【软件设计】理解面向对象编程(包含:概念,适用场景,特性等)

前言

创作开始时间:2021年7月29日15:07:42

一直在用面向对象编程,但是一直不求甚解,所以这里专门系统地回顾、研究一下。

1、概念

Object-oriented programming (OOP) is a programming paradigm based on the concept of “objects”, which can contain data and code: data in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods).

恍然大悟,原来如此。
面向对象编程将数据和代码分开。data用field的格式表示(即属性或者性质),code用过程的方式表示(即方法)。

思考:这样来看的话,面向对象似乎包括面向过程?因为面向对象的方法就是一个面向过程的实现。

2、适用场景

面向对象需要实例化对象, 开销比较大,所以一般单片机、嵌入式开发、Linux等开发都采用面向过程。

但是面向对象的好处是易于维护、复用、扩展。而且由于其特性,可以设计出低耦合的系统,使系统更加灵活,易于维护。

参考:2分钟让你明白什么是面向对象编程 https://zhuanlan.zhihu.com/p/75265007

3、特性

1. 封装(Encapsulation)

Encapsulation is an object-oriented programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse. Data encapsulation led to
the important OOP concept of data hiding.

对数据和方法的一种隐藏(设置访问权限等)。

2. 继承(inheritance)

This allows classes to be arranged in a hierarchy that represents “is-a-type-of” relationships.

方便扩展。

3. 多态(Polymorphism)

Subtyping – a form of polymorphism – is when calling code can be agnostic as to which class in the supported hierarchy it is operating on – the parent class or one of its descendants. Meanwhile, the same operation name among objects in an inheritance hierarchy may behave differently.

同一个hierarchy下的类都实现了同样名字的方法,所以即使在不知道具体是哪一类的时候,也可以调用同样的方法,实现不同的行为。

小结

以上。

创作结束时间:2021年7月29日15:25:15

参考文献

  1. wiki百科。(Object-oriented programming) 非常清楚
  2. What is Object Oriented Programming? OOP Explained in Depth https://www.educative.io/blog/object-oriented-programming
  3. 2分钟让你明白什么是面向对象编程 https://zhuanlan.zhihu.com/p/75265007
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值