Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
tjqgithub
javaDesignMode
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
test
Breadcrumbs
javaDesignMode
/
src
/
a08_Proxy
/
Test.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
23 lines (21 loc) · 1.16 KB
test
Breadcrumbs
javaDesignMode
/
src
/
a08_Proxy
/
Test.java
Copy path
Top
File metadata and controls
Code
Blame
23 lines (21 loc) · 1.16 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package
a08_Proxy
;
/**
* 代理模式 :
* 其实每个模式名称就表明了该模式的作用,代理模式就是多一个代理类出来,
* 替原对象进行一些操作,比如我们在租房子的时候回去找中介,为什么呢?
* 因为你对该地区房屋的信息掌握的不够全面,希望找一个更熟悉的人去帮你做,此处的代理就是这个意思。
* 再如我们有的时候打官司,我们需要请律师,因为律师在法律方面有专长,可以替我们进行操作,表达我们的想法。
*
* 代理模式的应用场景:
* 如果已有的方法在使用的时候需要对原有的方法进行改进,此时有两种办法:
* 1、修改原有的方法来适应。这样违反了“对扩展开放,对修改关闭”的原则。
* 2、就是采用一个代理类调用原有的方法,且对产生的结果进行控制。这种方法就是代理模式。
* 使用代理模式,可以将功能划分的更加清晰,有助于后期维护!
*
*/
public
class
Test
{
public
static
void
main
(
String
[]
args
) {
Sourceable
source
=
new
Proxy
();
source
.
method
();
}
}
You can’t perform that action at this time.