面向对象与面向过程

面向对象与面向过程

首先,我们解决问题一般都是将详细的步骤一步一步用代码的形式交给计算机处理,这个就是面向过程

而面向对象呢,毫无疑问就是针对这件事的对象的,就比如我们将要做一件事物,可以将具有相似功能的抽象为同一个对象,再通过调用每个对象的不同方法来解决问题。

例:我们要用洗衣机洗衣服

面向过程:

1:把洗衣机打开

2:把衣服放进洗衣机

3:往洗衣机里加水,加洗涤剂

4:关上洗衣机

5:设置程序(洗涤、脱水、烘干)后启动

面向对象:

我们将洗衣服这件事分为两个对象:人和洗衣机

再设置对象的方法以便调用。

人: 人.打开洗衣机 人.加水加洗涤剂 人.关上洗衣机

洗衣机: 洗衣机.洗涤 洗衣机.脱水 洗衣机.烘干等

我们只需要调用该对象的方法来解决问题

优缺点:

面向过程:

优点:性能比面向对象好,因为类的调用需要实例化,相比于面向过程往往会浪费一些性能。

缺点:一但前面的步骤出错了,后面的也会受到影响,并且不易扩展。

面向对象:

优点:易复用,易维护,易扩展,具有封装、继承、多态的特点,更好的设计出低耦合的系统

低耦合:就是事物的相关性吧,其中的一个改变对整体的影响不会很大。


刚开始学我也在想:这两个玩意不是差不多,没必要搞什么对象吧(我还没对象 呜呜~)

后来了解到,这些需要看你的需求是什么,再来决定用哪种方式。

就比如说Linux/Unix开发,这些在意性能的就选面向过程。

本文作者:傻孩子不吃辣

本文链接:https://www.cnblogs.com/Asillychild/p/16500322.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   傻孩子不吃辣  阅读(63)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 The Flood Joshua Hyslop
The Flood - Joshua Hyslop
00:00 / 00:00
An audio error has occurred.

作词 : Joshua Hyslop

作曲 : Joshua Hyslop

Here comes the flood again

Watch it fall from the sky

Feel it soak through my flesh and my blood

Feel it burn in my eyes

When I say how much more can I take?

I know the water’s rising up, watch the waves crest and break

And though I’ve made nothing but a sound

I fear that I may drown

I fear that I may drown

.

Here comes the wind again

Cold that cuts to the bone

Pack my bags and I’ll head out the door

Here I am on my own

When I say how much more can I stand?

I know my walls are falling down; I left the rocks and chose the sand

And though I’ve no one left to blame

Still, I cursed your name

I cursed your name

.

So now the end

What I’ve been running from

Though I’ve tried I cannot lift my head

Oh, what have I become?

When I say how much more can I take?

I know my time is running short, I am broken and I’ll break

And though I’ve worn myself so thin

I’m coming home again

And though I do not know my heart

Well, I know myself down to my bones, but if my bones should come apart

Then I’ll have nothing left to give

But if you take me in,

I’m coming home again

If you take me in

I’m coming home again