Design Patterns are common in Java. Are they equally important in other programming languages?

Source: Internet
Author: User
Is there a lot of design patterns in Java? Why is FP (FunctionalProgramming) unavailable? Is the design pattern in c ++ and python also important? Design Mode (
Design pattern) Is it used in Java? Why is FP (Functional Programming) not very useful? Is the design pattern in c ++ and python also important? Reply: There are two methods to study design patterns in a new language environment.

The first is to regard the first two chapters of design patterns as the essence of the book and the 23 pattern instances as examples. In the new environment, try to use the first two chapters to discover and organize the appropriate design patterns.

The second is to regard the first two chapters of "Design Patterns" as a general preface and 23 model instances as the essence of the book. Try to implement these 23 modes again in the new language environment and find their usage in the new environment.

The first was written in the "enterprise application architecture model", "xUnit test model", "enterprise integration model", and "restructuring" (mobile phone party, title of the book, written in memory for the moment, check again)

The second author wrote "dynamic languages are more advanced than static languages" and "talking about why ruby is better than Java in Design Patterns". let me show you how to use nine lines of code to implement the design pattern in python, and the net text such as "Java must die. (Well, the name is purely fabricated, But you know) C # is rarely used. C ++ will use a part, but it will not be used almost everywhere like Java.

The invention of the design pattern is mostly used to solve language defects. In FP, there is basically no object concept, and many design modes will naturally not be used. For Dynamic Language, many design patterns are basically not usable, and python incorporates some design patterns into the syntax, so it does not need to use the design patterns too much.

This is my answer to another question. Basically, I expressed my attitude towards the design pattern: There is no interface in Python. How do I write the design pattern? -Liu Qiming's answer design model is like Zhang Wuji's practice of Taijiquan.
First, you must be good at learning, but after learning, you should forget all of them and only integrate their spirit into your mind. In practice, do not develop a model by yourself. When the project is too long and the code is too much, you will find that although you did not deliberately use the design pattern, the code you write just hides the idea in a design pattern. The language can be divided into two types
1. Believe in programmers.
2. Do not trust programmers

Java does not trust programmers, so the design pattern is prevalent. Everything should follow the rules and regulations.

Python is intended for programmers. Even public/private Members of classes are just a convention.
The programmer forcibly calls the private method from the outside, and python will agree.

The typical setter/getter in Java cannot be seen in excellent python code.
Python also opposed the complexity of code writing.

Yin Shen used to specifically "decrypt" the design mode. Link: Wang Yin: decrypt the "design mode"
The core idea is,
When there is no design pattern, I write code like this.
The so-called mode is a summary of experience.
The copy mode is nothing more than the essence of things. In fact, it is impossible to design good things.
If you understand the mode, there is no need to write code in the mode.

My understanding is that the design model is necessary for learning. As for practice, there is no need to worry about the design model.

FP.
If we say that the design pattern is more of an experience summary.
Therefore, FP is a logic concept that requires the support of some features of the language.
Only the new version of Java supports FP. In the past, it was impossible to use FP instead of Java.
  1. The Design Pattern of GoF is not written in Java as an example. The examples are C ++ and small talk.
  2. As mentioned in the preface, the Design Pattern is Language-Specific and can only solve Specific problems in Specific languages.
  3. FP has its own set of things. No matter which one is called Design Pattern, it works the same as Design Pattern.
  4. Although a certain Pattern may be useless in a different language, the basic principle embodied in this Pattern is generally generic, you don't need to implement it on your own because the person who writes the syntax/standard library helps you.
FP has its own design model, such as Monad

As for the problems solved by the design model in java, because the functions in FP are first-class citizens, many problems do not exist, and naturally those models will not be used.
The design pattern is to implement these object-oriented principles, so as to achieve code reuse and increase maintainability.
The design pattern is just a tool, a means... the final goal is to write decoupled, reusable, and maintainable code...
Tools are not important, so the purpose is important... 1. design patterns are reusable general solutions in a given scenario. It is implemented by a column of best practices.
2. Any language has its own programming paradigm. In certain scenarios, there must be reusable solutions to solve the same problem.
3. The design pattern in java is the design pattern of the OO programming paradigm.
4. Even in the same OO language, there are significant differences in the Design Patterns of ruby and java best practices. Because ruby syntax is flexible and supports multi-paradigm.
5. The FP paradigm can be defined as a reusable general solution in a given scenario. For example, Pipeline, Observer, and Strategy
6. There is a broad view that there is no design pattern for FP. In OO, the design pattern is designed to make up for the defects of language features.

My personal opinion is:
If you use the current OO language to write code, the design mode is very important.
If you write FP, your implementation is to implement the design pattern. You have already discussed this issue many times. For details, see Are Design Patterns Missing Language Features.

Recommend a video
Pyvideo.org-Python Design Patterns 1
The speaker is my favorite Brandon Rhodes. In this video, he lists the applications of various design patterns in GOF in Python, which are directly removed because of Python's language features and which are still useful. In software engineering , Design patternIs a general reusable solution to a commonly occurring problem within a given context in software design

Do you think other languages should be available?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.