An example of Java design pattern

An example of Java design pattern

Design pattern thought

What is design pattern: as a beginner, I officially learned design pattern for the first time today. I think it is very important to understand what is design pattern, so what is design pattern?

Design pattern: an effective idea to solve problems.

Design pattern: a solution to specific problems that occur repeatedly in a specific environment

My understanding is that predecessors encountered a class of problems in software design, and they summarized a set of effective and verified solutions.

Advantages of design mode:

1. Design patterns are some relatively excellent solutions, and many problems are typical and representative problems. Learning design patterns, we don't have to solve these problems from scratch, which is equivalent to reusing these solutions on the shoulders of giants.

2. Design pattern has become a common vocabulary for professionals, which is not conducive to communication.

3. It can make the system you design more professional and make the system have a better architecture.

Design pattern 1 ~ ~ single example

Simple interest design pattern is used to solve the problem that there can only be one class in memory. This is more abstract. For example, if you want to play mahjong and throw dice, the first person loses several displayed numbers, and the later people also need to use them. Dice is only allowed to exist in memory. Such problems need to be solved by single case design.

The first type: the hungry man type comes out by himself first. Fast speed, only takes up more memory.

Second: lazy type

The synchronized lock belongs to the getInstance method. When the method belongs to static, the lock belongs to the class template. When the method is called by an object, the lock belongs to the object.

If you have any questions, please leave a message or go to the community of this site for exchange and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>