In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what are the design patterns in java development, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1) singleton mode
There is only one special class called singleton class in its core structure. Through the singleton mode, we can ensure that there is only one instance of a class in the system and the instance is easy to be accessed by the outside world, so as to facilitate the control of the number of instances and save system resources.
Application scenario: if you want only one object of a class to exist in the system, singleton mode is the best solution.
2) Factory mode
The factory pattern mainly provides an interface for creating objects.
The application scenarios are as follows:
It is impossible to foresee what kind of instance needs to be created when coding.
B. the system should not rely on the details of how product class instances are created, combined, and expressed.
3) Policy mode
Strategy pattern: algorithm families are defined and encapsulated so that they can be replaced with each other. This mode makes the change of the algorithm independent of the customer who uses the algorithm.
The application scenario is as follows.
A, one thing, there are many solutions can be achieved.
B. I can decide which implementation to use at any time.
C. more plans may be added in the future.
D, the strategy mode makes sure that the change of the scheme will not affect the customers who use the scheme.
An example business scenario is as follows.
The operation of the system must be logged, and the log is usually recorded in the database to facilitate subsequent management, but errors may occur when recording the log to the database, such as temporarily unable to connect to the database. Then record it in the file first. There are two algorithms for log writing to the database and the file, but the caller does not care and is only responsible for writing.
4) Observer mode
The Observer pattern, also known as the publish / subscribe pattern, defines one-to-many dependencies between objects. When an object changes its state, all its dependents are notified and updated automatically.
The application scenarios are as follows:
A. updating the state of one object requires synchronous updates of other objects, and the number of other objects is dynamically variable.
B. objects only need to notify other objects of their updates and do not need to know the details of other objects.
5) iterator mode
The iterator pattern provides a way to access elements in an aggregated object sequentially without exposing the internal representation of the object.
The application scenarios are as follows:
When you need to access an aggregate object and need to traverse no matter what those objects are, you should consider using the iterator pattern. The stl container is actually a good example of the iterator pattern.
6) template method mode
The template method pattern defines the skeleton of an algorithm in operation and delays some steps to the subclass. the template method enables the subclass to redefine some of the steps of the algorithm without changing the structure of the algorithm.
The application scenario is as follows: for some functions, different functions are shown on different objects, but the framework of the function is the same.
These are all the contents of the article "what are the design patterns in java development?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.