目录
- [1. 什么是面向对象?](#1. 什么是面向对象?)
- [2. 面向对象和面向过程](#2. 面向对象和面向过程)
- [3. 总结](#3. 总结)
1. 什么是面向对象?
是一种主要依靠对象之间的交互解决问题的思想。
2. 面向对象和面向过程
假设吃牛排
面向过程:如果在家,为了吃到好吃的牛排,需要关注做牛排的每个步骤不能出错。

而在高级餐厅,不关注做厨师是怎么做牛排的 ,只需要关注:通过服务员点单、厨师做牛排、服务员把做好的牛排端上来、服务员结账。也就是通过自己、服务员、厨师这3个对象之间的交互,最终吃到好吃的牛排。
#mermaid-svg-U0oA5NjZ6rEXZIX2{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-U0oA5NjZ6rEXZIX2 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .error-icon{fill:#552222;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .marker.cross{stroke:#333333;}#mermaid-svg-U0oA5NjZ6rEXZIX2 svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-U0oA5NjZ6rEXZIX2 p{margin:0;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .cluster-label text{fill:#333;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .cluster-label span{color:#333;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .cluster-label span p{background-color:transparent;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .label text,#mermaid-svg-U0oA5NjZ6rEXZIX2 span{fill:#333;color:#333;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .node rect,#mermaid-svg-U0oA5NjZ6rEXZIX2 .node circle,#mermaid-svg-U0oA5NjZ6rEXZIX2 .node ellipse,#mermaid-svg-U0oA5NjZ6rEXZIX2 .node polygon,#mermaid-svg-U0oA5NjZ6rEXZIX2 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .rough-node .label text,#mermaid-svg-U0oA5NjZ6rEXZIX2 .node .label text,#mermaid-svg-U0oA5NjZ6rEXZIX2 .image-shape .label,#mermaid-svg-U0oA5NjZ6rEXZIX2 .icon-shape .label{text-anchor:middle;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .rough-node .label,#mermaid-svg-U0oA5NjZ6rEXZIX2 .node .label,#mermaid-svg-U0oA5NjZ6rEXZIX2 .image-shape .label,#mermaid-svg-U0oA5NjZ6rEXZIX2 .icon-shape .label{text-align:center;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .node.clickable{cursor:pointer;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .arrowheadPath{fill:#333333;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-U0oA5NjZ6rEXZIX2 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-U0oA5NjZ6rEXZIX2 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-U0oA5NjZ6rEXZIX2 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .cluster text{fill:#333;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .cluster span{color:#333;}#mermaid-svg-U0oA5NjZ6rEXZIX2 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-U0oA5NjZ6rEXZIX2 rect.text{fill:none;stroke-width:0;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .icon-shape,#mermaid-svg-U0oA5NjZ6rEXZIX2 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .icon-shape p,#mermaid-svg-U0oA5NjZ6rEXZIX2 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .icon-shape .label rect,#mermaid-svg-U0oA5NjZ6rEXZIX2 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-U0oA5NjZ6rEXZIX2 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-U0oA5NjZ6rEXZIX2 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-U0oA5NjZ6rEXZIX2 :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 自己
服务员
厨师
3. 总结
| 面向过程 | 面向对象 |
|---|---|
| 关注"怎么做" | 关注"谁来做" |
| 以函数、步骤为中心 | 以对象为中心 |
| 强调执行流程 | 强调对象之间的协作 |