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
Small and medium teams
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 }}
AndroidYangKe
JavaDemo
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
JavaDemo
/
src
/
design_proxy
/
readme_proxy
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
executable file
·
36 lines (28 loc) · 1.48 KB
master
Breadcrumbs
JavaDemo
/
src
/
design_proxy
/
readme_proxy
Copy path
Top
File metadata and controls
Code
Blame
executable file
·
36 lines (28 loc) · 1.48 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
24
25
26
27
28
29
30
31
32
33
34
35
36
代理模式:
在代理模式中,一个类代表另一个类的功能。这种类型的设计模式属于结构性模式。在代理模式
中,我们创建具有现有对象的对象,以便向外界提供功能接口。
意图:
为其他对象提供一种代理以控制对这个对象的访问。
主要解决:
在直接访问对象时带来的问题。比如说:要访问的对象在远程的机器上。在面向对象系统中,有
些对象由于某些原因(比如对象创建开销很大,或者某些操作需要安全控制,或者需要进程外的
访问),直接访问会给使用者或者系统结构带来很多麻烦,我们可以在访问此对象时加上一个对
此对象的访问层。
何时使用:
在想访问一个类时做一些控制。
关键代码:
实现与被代理类组合。
应用实例:
* 桌面的快捷方式
* 买火车票不一定在火车站买,也可以去代售点
优点:
* 高拓展
* 智能化
* 职责清晰
缺点:
由于在客户端和真实主题之间增加了代理对象,因此有些类型的代理模式可能会造成请求的处理
速度变慢。实现代理模式需要额外的工作,有些代理模式的实现非常复杂。
注意事项:
* 和适配器模式的区别:适配器模式主要改变所考虑对象的接口,而代理模式不能改变
所代理类的接口。
* 和装饰器模式的区别:装饰器模式为了增强功能,而代理模式是为了加以控制。
You can’t perform that action at this time.