【翻譯】設計模式學習系列1---【Design Patterns Simplified: Part 1【設計模式簡化:第一部分】】

来源:http://www.cnblogs.com/caofangsheng/archive/2016/05/20/5512940.html
-Advertisement-
Play Games

http://www.c-sharpcorner.com/UploadFile/19b1bd/design-patterns-simplified-part1/ Design Patterns Simplified: Part 1【設計模式簡化:第一部分】 http://www.c-sharpcor ...


http://www.c-sharpcorner.com/UploadFile/19b1bd/design-patterns-simplified-part1/

Design Patterns Simplified: Part 1【設計模式簡化:第一部分】

 

 

Design patterns are an important consideration when designing or developing any software systems or solutions. There is so much buzz around patterns. At the same time, we often get confused about their use. Basically we get questions like the following:

        在設計或者開發任何軟體解決方案的時候,設計模式是一個重要的考慮因素。有這麼多都圍繞著設計模式,我們通常就會很疑惑關於設計模式的使用。基本上,我們的問題有下麵這些:

  •  What design patterns are【什麼是設計模式】
  •  Why to use them【為什麼要使用設計模式】
  •  When to use them【什麼時候使用設計模式】
  •  How many patterns we have【總共有多少設計模式】
In the first part of the series around design patterns, we will try to discuss and answer these questions. 在設計模式系列的第一部分,我們將會來討論和回答這些問題。

What design patterns are【什麼是設計模式】

Design patterns are basically proven solutions to common design problems. They can also be defined as recommended practices to solve any recurring problem in application design.

設計模式基本上是常見的設計問題的解決方案。他們同樣可以作為程式設計過程中反覆出現的問題的解決方案。

Please be clear that, design patterns are not ready-to-use code that can be used directly, instead they present approaches or recommendations to solve daily design challenges.

請清楚,設計模式不是現成的代碼,可以直接使用,相反,對於日常設計中出現的挑戰, 設計模式被用來提供方法或者建議。

Why to use them【為什麼要使用設計模式】

The reason for usign them is simple. Why re-invent the wheel, when we have workable, tested and well documented solutions for a set of common recurring problems?

       使用設計模式的原因很簡單。為什麼,要重覆造輪子?對於一系列反覆出現的問題,我們是否有可行的,容易測試的,並且有書面形式的解決方案麽?

We should use design patterns (when required) to design and develop reusable and scalable components that in turn helps the development team to finish the development activities in due time while attaining high quality.

       我們應該使用設計模式(在需要的時候)來設計和開發可重用和可擴展的組件,反過來幫助開發團隊在規定的時間內,高效,有質量地完成開發任務。

Designing an application in a standard or tested fashion also helps other developers and code reviewers to understand the written code easily.

以一個標準設計應用程式,同樣是幫助其他的開發者和代碼Review人員更好的測試並理解代碼是怎麼寫的。

 

When to use them【什麼時候使用設計模式】


 

This is a very pertinent issue and we should be well aware of their usefulness. Using design patterns without evaluating them properly can make the design unnecessarily complex.

       這是一個非常中肯的問題,我們應該清楚設計模式的適用性。使用設計模式的時候,沒有很好的評估,將會使得設計變得不必要的複雜。

There could be instances when you might not need them at all and you can simply live with basic OOP design principles.

   可能存在這樣的情況:你可能不需要設計模式,你可以簡單地使用基本的面向對象設計原則。

Whether to use them or not depends on the scenario at hand. Each pattern talks about specific design problems and the standard solution for that. So before using them, spend a fair amount of time in analyzing your design issues and try to match it with the once-discussed in patterns.

是否使用設計模式,取決於你的實際情況。每個模式討論特定的設計問題和標準的解決方案。所以在使用它們之前,花點時間,來分析你的設計問題,試圖使用一種設計模式來與之對應,那麼就可以使用這個模式,來解決你的設計問題了。

I would like to emphasize the point that the key to find the right pattern is to understand and identify the scenario that any pattern is trying to address.

我想強調一點,找到合適的模式的關鍵是理解和識別用什麼設計模式來解決問題。

Once you find the right pattern for your specific problem or scenario, you can apply it to your software design.

只要你發現了適用你的問題的模式,你就可以應用它,來解決你的軟體設計出現的問題。

The many patterns【總共有多少設計模式】

There is no specific number of patterns, since they kind of evolve over time and the software industry has used and tested them. Having said that, there are folks like the “Gang of Four” that have well-documented and popularized them in the software development community. I also find SOLID design principles to be worth refer to.

這裡沒有固定數量的設計模式,因為軟體行業使用和測試的設計模式,隨時間而變化。說道這裡,例如“Gang of Four”在軟體社區很受歡迎。我也發現可靠的設計原則是值得參考的。

To summarize the discussion, I would like to say to start your design with a few basic design principles, like clean coding, loose coupling and modular design and so on and continue to evaluate design challenges with known and existing issues discussed in design patterns. After evaluation, if you find any matching pattern then go ahead and use it else stick to whatever you have designed.

       最後總結一下,我想說的是,開始考慮你的設計使用一些設計原則,例如,乾凈的Coding,松耦合,模塊化設計等等,並且在你面臨設計挑戰的時候,評估設計模式中已知和已經存在的問題。評估完之後,你會發現能夠解決你的問題的設計模式,那麼就趕緊使用,推翻你之前的設計。

One last thing. Please don't force your application to use design patterns. Instead use them only if it makes sense.

最後一件事,不要強制應用設計模式到你的程式中。只有當應用設計模式的時候,能夠解決問題,才去使用它。

I hope you have liked the article. Please share your comments.

我希望你喜歡這篇文章,請留下你的評論,謝謝~~~.


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 責任鏈模式 使多個對象都有機會處理請求,從而避免請求的發送者和接受者之間的耦合關係。將這些對象連成一條鏈,並沿著這條鏈檢查該請求,並對其進行處理,或者將它傳遞給下一個對象。 責任鏈模式有兩個角色組成: 抽象處理者角色:它定義了一個處理請求的介面。當然對於鏈子的不同實現,也可以在這個角色中實現後繼鏈。 ...
  • 1單例設計模式 在一個類中只存在此類的唯一對象被共用。 2 類比 我們假設一個家庭裡面只有一個廁所WC,那個作為廁所類,WC在整個家庭裡面是唯一的,如果我們要去用WC,那麼家庭成員的人員應該排隊去用WC。 3 代碼 ...
  • 互聯網的發展,網站應用的規模不斷擴大,常規的垂直應用架構已無法應對,分散式服務架構以及流動計算架構勢在必行,Dubbo是一個分散式服務框架,在這種情況下誕生的。現在核心業務抽取出來,作為獨立的服務,使前端應用能更快速和穩定的響應。 第一:介紹Dubbo背景 大規模服務化之前,應用可能只是通過RMI或 ...
  • 原創文章,同步發自 "作者個人博客" "http://www.jasongj.com/design_pattern/flyweight/" 。轉載請註明出處 享元模式介紹 享元模式適用場景 面向對象技術可以很好的解決一些靈活性或可擴展性問題,但在很多情況下需要在系統中增加類和對象的個數。當對象數量太 ...
  • 建造者模式:將一個複雜對象的構建與它的表示分離,使得同樣的構建過程可以創建不同的表示。(轉至《大話設計模式》)。 學習這個模式後,不知覺得和之前的簡單工廠模式做了對比,發現二者都是創建對象。但二者還是有所區別的,簡單工廠模式是更具不同的情況創建不同的對象, 而建造者模式則主要是用於創建一些複雜的對象 ...
  • 1.意圖 將一個類介面轉換成客戶希望的另外一個介面。Adapter模式使那些原本不能一起工作的類,可以一起工作。 2.別名 包裝器 Wrapper. 3.動機 一個應用可能會有一些類具有不同的介面,並且這些介面互不相容,可以專門定義一個類,用來適配互不相容的類。 4.適用性 你想使用一個已經存在的類 ...
  • 命令模式 將“請求”封裝成對象,以便使用不同的請求、隊列或者日誌來參數化其他對象。命令模式也支持可撤銷的操作。 說明: 1、命令模式將發出請求的對象和執行請求的對象解耦; 2、在被解耦的兩者之間是通過命令對象進行溝通的。命令對象封裝了接受者和一個或一組動作; 3、調用者通過調用命令對象的execut ...
  • 系統環境: centos6.7 jdk-7u79-linux-x64 apache-tomcat-7.0.57 apr-1.5.2 apr-util-1.5.4 一、tomcat安裝 二、測試 獲取下載地址 springmvc4 mybatis 整合 框架源碼 bootstrap html5 三、配 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...