程序设计方法及模式
Tags: pattern, gof
Published: 2017-10-09 06:46:57

---
title: ç¨‹åºè®¾è®¡æ–¹æ³•åŠæ¨¡å¼
published: true
description: ä»‹ç»å¸¸ç”¨çš„ç¨‹åºè®¾è®¡æ–¹æ³•åŠæ¨¡å¼
tags: pattern, gof
---

###[å‘ç”Ÿåœ¨å¥½ä»£ç ä¸Šçš„åäº‹æƒ…ï»¿ï»¿](http://swreflections.blogspot.ca/2012/10/bad-things-happen-to-good-code.html)
* å¦¥åçš„åŠ›é‡
* è¿­ä»£å¼€å‘å…·æœ‰è…èš€æ€§
* å¯¹ä»˜è½¯ä»¶çš„ä¸æ–­è”“å»¶

###[ç¼–ç å¥½ä¹ æƒ¯ï»¿](https://dev.to/tonyhicks20/good-coding-manners-d3e)
The key to good communication is simplicity. å¥½æ²Ÿé€šçš„å…³é”®åœ¨äºŽç®€æ˜Žè€Œè¦ã€‚
* æž¶æž„ï»¿

Have the code flow logically and clearly. è®©ä»£ç åˆä¹Žé€»è¾‘åˆæ¸…æ™°ã€‚
* æ¸…ç†æŽ‰ä¸ç”¨çš„ä»£ç 
* ä¸€è‡´æ€§
* ä»…ä»…å› ä¸ºä½ ä¼šåšä»€ä¹ˆï¼Œå¹¶ä¸æ„å‘³ç€ä½ åº”è¯¥é‚£ä¹ˆåš
* æ³¨é‡Šå’Œæ–‡æ¡£
* ç»™ä»£ç æ³¨é‡Šæ—¶åº”å†™æ˜Žä¸ºä»€ä¹ˆï¼Œè€Œä¸æ˜¯åšäº†ä»€ä¹ˆ

###[â€œè®¾è®¡â€ä½ çš„ä»£ç ](http://www.blogjava.net/johnnylzb/archive/2010/04/28/319551.html)
* è®²è¿°å¦‚ä½•ä»Žâ€œè¿‡ç¨‹å¼â€ç¼–ç è½¬ä¸ºâ€œé¢å‘å¯¹è±¡å¼â€ç¼–ç ã€‚
* â€œè¿‡ç¨‹å¼â€ç¼–ç çš„ä¸€ä¸ªæ˜¾è‘—ç‰¹å¾å°±æ˜¯æ–¹æ³•æˆ–ç±»å·¨å¤§ï¼Œæ¯”å¦‚æ–¹æ³•ä½“é€»è¾‘å¤æ‚ï¼Œä»Žè€Œè¶…è¿‡ 200 è¡Œï¼Œç±»è¶…è¿‡ 1000 è¡Œï¼›å…¶ä»–ç‰¹å¾æœ‰ï¼Œ ç¹å¤šæˆ–åµŒå¥—çš„ if...else è¯­å¥ã€‚

###[å…³äºŽä¸šåŠ¡é€»è¾‘åˆ†ç¦»çš„ç®€å•ä¾‹å­](http://www.blogjava.net/johnnylzb/archive/2010/04/27/319527.html)
* ä¸šåŠ¡é€»è¾‘çš„å¤æ‚åº¦ä¸åº”è¯¥å½±å“è®¾è®¡çš„åˆç†æ€§ã€‚æ¯”å¦‚ï¼Œå³ä¾¿æ˜¯å¾ˆç®€å•çš„ä¸šåŠ¡é€»è¾‘ï¼Œä¹Ÿåº”åˆ’åˆ†æ¸…æ¥šå…¶æ‰€å±žä½ç½®ï¼Œç‰¹åˆ«æ˜¯åº”ç”¨åˆ°å‰åŽç«¯åˆ†ç¦»çš„ç³»ç»Ÿä¸­æ—¶ã€‚

###è®¾è®¡æ¨¡å¼
|ç±»åž‹|æ¨¡å¼åç§°|å­¦ä¹ éš¾åº¦|ä½¿ç”¨é¢‘çŽ‡|
| :------:   | :----:  | :----:  | :----:  |
|åˆ›å»ºåž‹æ¨¡å¼ Creational Pattern|å•ä¾‹æ¨¡å¼Singleton Pattern|â˜…â˜†â˜†â˜†â˜†|â˜…â˜…â˜…â˜…â˜†|
|åˆ›å»ºåž‹æ¨¡å¼ Creational Pattern|ç®€å•å·¥åŽ‚æ¨¡å¼ Simple Factory Pattern|â˜…â˜…â˜†â˜†â˜†|â˜…â˜…â˜…â˜†â˜†|
|åˆ›å»ºåž‹æ¨¡å¼ Creational Pattern|å·¥åŽ‚æ–¹æ³•æ¨¡å¼ Factory Method Pattern|â˜…â˜…â˜†â˜†â˜†|â˜…â˜…â˜…â˜…â˜…|
|åˆ›å»ºåž‹æ¨¡å¼ Creational Pattern|æŠ½è±¡å·¥åŽ‚æ¨¡å¼ Abstract Factory Pattern|â˜…â˜…â˜…â˜…â˜†|â˜…â˜…â˜…â˜…â˜…|
|åˆ›å»ºåž‹æ¨¡å¼ Creational Pattern|åŽŸåž‹æ¨¡å¼ Prototype Pattern|â˜…â˜…â˜…â˜†â˜†|â˜…â˜…â˜…â˜†â˜†|
|åˆ›å»ºåž‹æ¨¡å¼ Creational Pattern|å»ºé€ è€…æ¨¡å¼ Builder Pattern|â˜…â˜…â˜…â˜…â˜†|â˜…â˜…â˜†â˜†â˜†|
|ç»“æž„åž‹æ¨¡å¼ Structural Pattern|é€‚é…å™¨æ¨¡å¼ Adapter Pattern|â˜…â˜…â˜†â˜†â˜†|â˜…â˜…â˜…â˜…â˜†|
|ç»“æž„åž‹æ¨¡å¼ Structural Pattern|æ¡¥æŽ¥æ¨¡å¼ Bridge Pattern|â˜…â˜…â˜…â˜†â˜†|â˜…â˜…â˜…â˜†â˜†|
|ç»“æž„åž‹æ¨¡å¼ Structural Pattern|ç»„åˆæ¨¡å¼ Composite Pattern|â˜…â˜…â˜…â˜†â˜†|â˜…â˜…â˜…â˜…â˜†|
|ç»“æž„åž‹æ¨¡å¼ Structural Pattern|è£…é¥°æ¨¡å¼ Decorator Pattern|â˜…â˜…â˜…â˜†â˜†|â˜…â˜…â˜…â˜†â˜†|
|ç»“æž„åž‹æ¨¡å¼ Structural Pattern|å¤–è§‚æ¨¡å¼ FaÃ§ade Pattern|â˜…â˜†â˜†â˜†â˜†|â˜…â˜…â˜…â˜…â˜…|
|ç»“æž„åž‹æ¨¡å¼ Structural Pattern|äº«å…ƒæ¨¡å¼ Flyweight Pattern|â˜…â˜…â˜…â˜…â˜†|â˜…â˜†â˜†â˜†â˜†|
|ç»“æž„åž‹æ¨¡å¼ Structural Pattern|ä»£ç†æ¨¡å¼ Proxy Pattern|â˜…â˜…â˜…â˜†â˜†|â˜…â˜…â˜…â˜…â˜†|
|è¡Œä¸ºåž‹æ¨¡å¼ Behavioral Pattern|èŒè´£é“¾æ¨¡å¼ Chain of Responsibility Pattern|â˜…â˜…â˜…â˜†â˜†|â˜…â˜…â˜†â˜†â˜†|
|è¡Œä¸ºåž‹æ¨¡å¼ Behavioral Pattern|å‘½ä»¤æ¨¡å¼ Command Pattern|â˜…â˜…â˜…â˜†â˜†|â˜…â˜…â˜…â˜…â˜†|
|è¡Œä¸ºåž‹æ¨¡å¼ Behavioral Pattern|è§£é‡Šå™¨æ¨¡å¼ Interpreter Pattern|â˜…â˜…â˜…â˜…â˜…|â˜…â˜†â˜†â˜†â˜†|
|è¡Œä¸ºåž‹æ¨¡å¼ Behavioral Pattern|è¿­ä»£å™¨æ¨¡å¼ Iterator Pattern|â˜…â˜…â˜…â˜†â˜†|â˜…â˜…â˜…â˜…â˜…|
|è¡Œä¸ºåž‹æ¨¡å¼ Behavioral Pattern|ä¸­ä»‹è€…æ¨¡å¼ Mediator Pattern|â˜…â˜…â˜…â˜†â˜†|â˜…â˜…â˜†â˜†â˜†|
|è¡Œä¸ºåž‹æ¨¡å¼ Behavioral Pattern|å¤‡å¿˜å½•æ¨¡å¼ Memento Pattern|â˜…â˜…â˜†â˜†â˜†|â˜…â˜…â˜†â˜†â˜†|
|è¡Œä¸ºåž‹æ¨¡å¼ Behavioral Pattern|è§‚å¯Ÿè€…æ¨¡å¼ Observer Pattern|â˜…â˜…â˜…â˜†â˜†|â˜…â˜…â˜…â˜…â˜…|
|è¡Œä¸ºåž‹æ¨¡å¼ Behavioral Pattern|çŠ¶æ€æ¨¡å¼ State Pattern|â˜…â˜…â˜…â˜†â˜†|â˜…â˜…â˜…â˜†â˜†|
|è¡Œä¸ºåž‹æ¨¡å¼ Behavioral Pattern|ç­–ç•¥æ¨¡å¼ Strategy Pattern|â˜…â˜†â˜†â˜†â˜†|â˜…â˜…â˜…â˜…â˜†|
|è¡Œä¸ºåž‹æ¨¡å¼ Behavioral Pattern|æ¨¡æ¿æ–¹æ³•æ¨¡å¼ Template Method Pattern|â˜…â˜…â˜†â˜†â˜†|â˜…â˜…â˜…â˜†â˜†|
|è¡Œä¸ºåž‹æ¨¡å¼ Behavioral Pattern|è®¿é—®è€…æ¨¡å¼ Visitor Pattern|â˜…â˜…â˜…â˜…â˜†|â˜…â˜†â˜†â˜†â˜†|
###æ ¹æ®ç›®çš„å’ŒèŒƒå›´å¯¹è®¾è®¡æ¨¡å¼è¿›è¡Œåˆ†ç±»
![æ ¹æ®ç›®çš„å’ŒèŒƒå›´å¯¹è®¾è®¡æ¨¡å¼è¿›è¡Œåˆ†ç±»](https://thepracticaldev.s3.amazonaws.com/i/pe2ttugmmk0kmgmpds6m.png)
###è®¾è®¡æ¨¡å¼ç±»å›¾
![è®¾è®¡æ¨¡å¼ç±»å›¾](https://thepracticaldev.s3.amazonaws.com/i/qb9uc6w08t285fl1k0yr.png)