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【總共有多少設計模式】
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.
我希望你喜歡這篇文章,請留下你的評論,謝謝~~~.