Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
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 }}
askYangc
algorithm
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
algorithm
/
design_patterns
/
facade
/
main.cpp
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
47 lines (33 loc) · 1.7 KB
master
Breadcrumbs
algorithm
/
design_patterns
/
facade
/
main.cpp
Copy path
Top
File metadata and controls
Code
Blame
47 lines (33 loc) · 1.7 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
37
38
39
40
41
42
43
44
45
46
#
include
"
facade.h
"
/*
迪米特法则(LoD)
如果两个类不必彼此直接通信,那么这两个类就不应当发生直接的相互作
用,如果其中一个类需要调用另外一个类的某个方法,可以通过第三者转
发这个调用。
迪米特法则主要是强调类之间的松耦合。类之间的耦合越弱,越有利于复
用。尽量降低类与类之间的联系。
外观模式
最常用的模式之一。
即用一个类Facade包装了整个系统,调用者不需要了解具体的实现细节。
只需要知道类提供的接口就可以了。
外观模式使用场景
在设计初期阶段,就应该要有意识的将不同的两个层分开,比如经典三层
架构,需要考虑在数据访问层、业务逻辑层、表示层的层与层之间建立外
观Facade,这样可以为复杂的子系统提供一个简单的接口。降低耦合。
其次在开发阶段,子系统可能会创建越来越多的类,但是调用的用户程序
是不需要知道的,所以这里增加外观Facade可以提供一个简单的接口,减
少依赖。第三,在维护一个遗留的系统,如果有新需求,需要开发新系统
,那么最好要做一个Facade类,隔离掉用新系统与旧系统,让锡系统与
Facade对象交互,Facade与旧系统交互。
*/
//
如果在cpp里面包含c定义的头文件
extern
"
C
"
{
}
int
main
(
int
argc,
char
**argv)
{
team a;
a.
do_operationA
();
//
其他模块不需要了解内部的实现方式,只需要知道有这个API就可以了,内部由类自己实现
std::cout <<
"
-----------
"
<< std::endl;
a.
do_operationB
();
//
这样就隔离了用户程序和内部的子系统。实现了迪米特法则
return
0
;
}
You can’t perform that action at this time.