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 }}
OneCodeOneTime
DesignPatternsJava
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
iterator
Breadcrumbs
DesignPatternsJava
/
src
/
Template
/
FrameWork.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
50 lines (45 loc) · 1.35 KB
iterator
Breadcrumbs
DesignPatternsJava
/
src
/
Template
/
FrameWork.java
Copy path
Top
File metadata and controls
Code
Blame
50 lines (45 loc) · 1.35 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
47
48
49
50
package
Template
;
/**
* 定义:定义一个操作中算法的框架,而将一些步骤延迟到子类中,使得子类可以不改变算法的结构即可重定义该算法中的某些特定步骤。
* 思想:主框架相同,细节不同。
* 和策略模式的不同点:策略模式就是定义算法族, 然后通过组合算法族和委托的办法来实现类, 模板方法则是父类定义算法的骨架,子类再来实现骨架中的部分步骤。
* @Component:抽象模板(Abstract Template):
* ①给出一个逻辑流程的完整框架方法,流程中的方法可以是具体方法或抽象方法,实现一个业务或算法逻辑。
* ②定义流程框架中的抽象方法,待子类实现。
* @author btp
*
*/
public
abstract
class
FrameWork
{
/*
* 模板方法:搭建逻辑框架,比如业务流程,一般修饰为final,防止子类的重写
*/
public
final
void
LogicFrameWork
(){
//完整的逻辑流程
regularStep1
();
if
(
doJudge
()){
regularStep2
();
}
variableStep1
();
variableStep2
();
}
/*
* 普通方法:逻辑框架中的固定步骤,一般子类最好不建议重写这部分的方法,代表了流程中的固定部分。
*/
void
regularStep1
(){
System
.
out
.
println
(
"FrameWork.regularStep1()"
);
}
void
regularStep2
(){
System
.
out
.
println
(
"FrameWork.regularStep2()"
);
}
/*
* 钩子方法(Hook Method):一般提供空实现,子类去拓展,从而达到影响逻辑的效果。
*/
boolean
doJudge
(){
return
false
;
}
/*
* 抽象方法:逻辑框架中的可变步骤,交由子类实现
*/
abstract
void
variableStep1
();
abstract
void
variableStep2
();
}
You can’t perform that action at this time.