In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to use the agent design pattern in the java interface". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use the agent design pattern in the java interface.
Concept: two subclasses work together to implement an interface, one of which is responsible for the real business implementation, and the other is responsible for assisting the real business theme.
Package www.miao.java;interface ISubject {/ / the core function is to buy a computer public void buyComputer ();} / real business implementation class RealSubject implements ISubject {public void buyComputer () {System.out.println ("buy an alien computer");}} class proxySubject implements ISubject {/ / real operation business private ISubject subject; public proxySubject (ISubject subject) {this.subject = subject;} public void produceComputer () {System.out.println ("production of alien computers") } public void afterSale () {System.out.println ("after-sale of alien computers");} public void buyComputer () {/ / prepare this.produceComputer () before real operation; / / call real business this.subject.buyComputer (); / / wrap up this.afterSale () after operation;}} class Factory {public static ISubject getInstance () {return new proxySubject (new RealSubject ()) }} public class Test {public static void main (String [] args) {ISubject subject = Factory.getInstance (); subject.buyComputer ();}}
At this point, I believe you have a deeper understanding of "how to use the agent design pattern in the java interface". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.