In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces how to realize the opening and closing principle in Springboot. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Without knowing the tedious design patterns, Springboot can help us to realize the opening and closing principle simply and conveniently.
If an object has multiple states (states are likely to increase), each state corresponds to a processing method, if if is used. Else... Each time a state is added, the original code needs to be changed, and the business that has moved the code needs to be retested in principle, which increases the burden on development, maintenance and testing. Springboot has a very useful feature, which makes it easy to get a collection of classes that implement an interface or inherit a class.
Define your own interface or abstract class first
Public interface MyInterface {String m ();}
Define classes that specifically implement methods in the interface
@ Service ("prevent duplicate prefixes _ status codes") public class MyClassA implements MyInterface {@ Override public String m () {/ / A's business return "A";}} @ Service ("prevent duplicate prefixes _ status codes") public class MyClassB implements MyInterface {@ Override public String m () {/ / B's business return "B";}}
Use
@ RestControllerpublic class MyController {@ Autowired Map myInterfaceMap; @ GetMapping ("/ api/ {status}") public String testStatus (@ PathVariable String status) {return myInterfaceMap.get ("prevent repetition prefix _" + status). M ();} about how to implement the opening and closing principle in Springboot. I hope the above can be helpful and learn more. If you think the article is good, you can share it for more people to see.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.