Design mode (
is the design pattern more in Java? Why does the FP (functional programming) not work? Is it important to design patterns in C++,python?
Reply content:
There are two ways to study design patterns in a new language environment.
The first is to consider the first two chapters of design mode as the essence of the book, and consider 23 examples of patterns as illustrative examples. In the new environment, try to use the first two chapters of the idea to find and organize the appropriate design patterns.
The second is to consider the first two chapters of the design pattern as a preface to the generalities, and consider the 23 model examples as the essence of the book. In the new locale, try to re-implement these 23 patterns and look for their usage in the new environment.
The first kind of people wrote the "Enterprise Application Architecture Model", "Xunit test Mode", "Enterprise Integration Model", "refactoring" such books (Mobile Party, the title of the book is written by memory, have the opportunity to proofread)
The second kind of person wrote "dynamic language than static language advanced", "from design mode to talk about why Ruby finished Java", "Let me tell you how to use nine lines of code in Python implementation design mode," Java Must Die "and so on. (Well, the name is purely fictional, but you know) in C # also used is not very small, C + + will use a part, but not like Java almost everywhere in use.
The invention of design pattern, more is to solve the language flaw use means. There is basically no concept of objects in the FP, and many design patterns are not naturally available. For a dynamic type of language, many design patterns are largely unused, and Python incorporates the idea of a part of the design pattern into the syntax, without the need to use design patterns too much.
This is my answer in another question, which basically expresses my attitude to design patterns: There is no interface in Python, how to write design patterns? -Lau's answer design pattern is like Zhang Mowgli learning Taijiquan.
First of all, it is better to learn, but after learning should forget all of them, only the spirit into the brain. Then in practice, do not go to mechanically a pattern, but to design their own. And so on, the code to write more, you will find that although you did not deliberately use design patterns, but you write out of the code just coincidence a design mode of thinking. Language can be divided into 2 kinds
1. Trust the programmer.
2. Don't trust the programmer
Java does not believe in programmers, so design patterns prevail. Everything has to go according to the rules.
Python is a public/private member of a class that believes in programmers, and is just a convention.
The programmer forcibly calls the private method externally, and Python will agree.
The typical setter/getter in Java is not visible in the good Python code.
Python's father also objected to the complexity of writing the code.
Yin God has specifically "decrypted" the design mode, Link: Wang Yin: decryption "design mode"
The core idea is that
I write code like this when there is no design pattern.
The so-called pattern is the summary of experience.
Copy the pattern patchwork, but can not see through the essence of things, in fact, is not the design of good things.
If you understand the pattern, there is no need to follow the pattern to write the code.
My understanding, design patterns, learning is a must. As for the actual combat time. There is no need to care about what design patterns are used.
About FP.
If you say, design pattern, more is a kind of experience summary.
Then, FP is a logical way of thinking, it is necessary to have some characteristics of language support.
FP is only supported for new versions of Java. Previously, it was not Java with a FP, but it couldn't be used at all.
- Gof's design pattern is not written in Java, examples of which are C + + and small Talk
- In the preface, it has been said that Design pattern is language specific and can only solve specific language specific problems.
- FP has its own set of things, regardless of which is called design pattern, but the role of design pattern is the same.
- Although some pattern may not be used in any other language, the basic principles embodied in this pattern are usually universal, and you do not need to do it yourself just because the person who wrote the grammar/standard library helped you.
FP has its own design pattern, such as Monad
As for the Java design model to deal with the problem, because the FP function is a class of citizens, so many problems do not exist, nature will not use those patterns.
design pattern is the realization of these object-oriented principles, so as to achieve code reuse, increase maintainability.
Design pattern is just a tool, a means ... The ultimate is to write decoupling, multiplexing, maintainable code ...
Tools are unimportant, purpose is important ... 1. The design pattern is a reusable universal solution for a given scenario. It is implemented by a list of best practices.
2. Any language has its own programming paradigm, and using this paradigm to solve the same problem in a certain scenario must have a reusable solution.
3. The design pattern in Java is the design pattern of the OO programming paradigm.
4. Even in the same OO language, the design patterns for best practices in Ruby and Java are significantly different. Because Ruby syntax is flexible and supports multiple paradigms.
5. The FP paradigm can be defined as a reusable universal solution in a given scenario. such as Pipeline,observer,strategy, etc.
6. There is a broad view that FP has no design pattern. The existence of design patterns in OO is to compensate for the shortcomings of linguistic features.
My personal point of view is:
If you write code in the current OO language, then design mode is important.
If you write the FP, then your implementation itself is designed to implement the design pattern. There has been a lot of discussion about this question, see is Design Patterns Missing Language Features
Recommend a video
Pyvideo.org-python Design Patterns 1
The speaker is the Brandon I admire very much Rhodes
, in this video, he cites the various design patterns in GOF in Python, which are still useful because of the direct disappearance of Python's language features. In Software engineering
A
design pattern is a general reusable solution to a commonly occurring problem within a given context in software design
Do you feel that other languages should not have?