惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
大猫的无限游戏
大猫的无限游戏
Security Latest
Security Latest
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
IT之家
IT之家
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
博客园 - Franky
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Simon Willison's Weblog
Simon Willison's Weblog
S
Securelist
T
Threatpost
Last Week in AI
Last Week in AI
P
Privacy International News Feed
S
SegmentFault 最新的问题
aimingoo的专栏
aimingoo的专栏
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
Cisco Talos Blog
Cisco Talos Blog
T
Tailwind CSS Blog
Blog — PlanetScale
Blog — PlanetScale
G
GRAHAM CLULEY
GbyAI
GbyAI
G
Google Developers Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
B
Blog RSS Feed
A
About on SuperTechFans
H
Help Net Security
T
Threat Research - Cisco Blogs
C
Check Point Blog
S
Schneier on Security
Google DeepMind News
Google DeepMind News
T
The Exploit Database - CXSecurity.com
博客园 - 叶小钗
Scott Helme
Scott Helme
博客园 - 司徒正美
美团技术团队
W
WeLiveSecurity
O
OpenAI News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
AWS News Blog
AWS News Blog
I
InfoQ

博客园 - ®Geovin Du Dream Park™

go: Functional Options Pattern go:Timing Functions Pattern python: Timing Functions Pattern go: Steady-State Pattern python: Steady-State Pattern go: Handshaking Pattern python: Handshaking Pattern go: Fail-Fast Pattern python: Fail-Fast Pattern I go: Deadline Pattern python: Deadline Pattern go: Circuit-Breaker Pattern python: Circuit-Breaker Pattern go: Bulkheads Pattern python: Bulkheads Pattern go: Push & Pull Pattern python: Push & Pull Pattern python: Publish/Subscribe Pattern II go: Publish/Subscribe Pattern python: Publish/Subscribe Pattern go: Futures & Promises Pattern python: Futures & Promises Pattern go: Worker Pool Pattern go:Pipeline Pattern python: Worker Pool Pattern python: Pipeline Pattern go: Fan-Out Pattern python: Fan-Out Pattern go: Fan-In Pattern python: Fan-In Pattern Fan-In go: Producer Consumer  Pattern python: Producer Consumer Pattern go: Parallelism Pattern python: Parallelism Pattern go: Reactor Pattern python: Reactor Pattern go: Generators Pattern python: speech to text offline python: Generators Pattern go: Coroutines Pattern python:Coroutines Pattern go: Broadcast Pattern python: Broadcast Pattern python: Bounded Parallelism Pattern go: Bounded Parallelism Pattern python: N-Barrier Pattern go: N-Barrier Pattern python: Semaphore Pattern go: Semaphore Pattern python: Read-Write Lock Pattern go: Read-Write Lock Pattern python: Monitor Pattern go: Monitor Pattern python: Mutex Pattern go: Lock/Mutex Pattern Python: Condition Variable Pattern go:Condition Variable Pattern python: Registry Pattern python: Interpreter Pattern go: Interpreter Pattern go: Registry Pattern go: Memento Pattern go: Command Pattern go: State Pattern go: Strategy Pattern go: Visitor Pattern go: Observer Pattern go: Mediator Pattern go: Iterator Pattern go: Chain of Responsibility Pattern go: Proxy Pattern go:Decorator Pattern go: Facade Pattern go: Flyweight Pattern go: Composite Pattern go: Singleton Pattern go: Prototype Pattern go: Bridge Pattern go: Adapter Pattern go: Builder Pattern 密码进行加盐哈希 using CSharp,Python,Go,Java go: Abstract Factory Pattern go: Model,Interface,DAL ,Factory,BLL using mysql go: Simple Factory Pattern go: Factory Method Pattern go: goLang 在Windows环境搭建Go语言开发环境 CSharp: Parallel Extensions cpp: class python: 蝴蝶跟随鼠标 javascript: 中国历史人物热力分布图using echart javascript: 中国历史人物热力图 python: 初养龙虾微信纯文字自动回复using workBuddy python: object 入门 python: Factory Method Pattern python: Simple Factory Pattern python: Abstract Factory Pattern 区域化 代码 python: Null Object Pattern python: Builder Pattern python: Adapter Pattern
go:Template Method Pattern
®Geovin Du Dream Park™ · 2026-04-25 · via 博客园 - ®Geovin Du Dream Park™

项目结构:

image

/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Template Method Pattern  模板方法模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/4/25 10:09
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : jewelry_template.go
*/
package template

import (
	"fmt"
	"godesginpattern/templatemethod/entity"
)

// 珠宝制作模板(算法骨架)
type JewelryTemplate struct {
	jewelry entity.Jewelry // 依赖接口,面向抽象编程
}

// NewJewelryTemplate 构造函数(企业级必须用构造函数)
func NewJewelryTemplate(j entity.Jewelry) *JewelryTemplate {
	return &JewelryTemplate{jewelry: j}
}

// Make 模板方法:对外暴露标准制作流程
func (t *JewelryTemplate) Make() {
	t.selectMaterial()               // 1. 选材(通用)
	fmt.Println(t.jewelry.Shaping()) // 2. 塑形(可变)
	t.polish()                       // 3. 打磨(通用)
	fmt.Println(t.jewelry.Inlay())   // 4. 镶嵌(可变)
	t.qualityCheck()                 // 5. 质检(通用)
	t.finish()                       // 6. 成品(通用)
}

// 以下为 通用步骤(私有方法,禁止外部调用)
func (t *JewelryTemplate) selectMaterial() {
	fmt.Println("[通用] 选材:甄选贵金属与天然宝石")
}

func (t *JewelryTemplate) polish() {
	fmt.Println("[通用] 打磨:镜面抛光处理")
}

func (t *JewelryTemplate) qualityCheck() {
	fmt.Println("[通用] 质检:符合国家珠宝生产标准")
}

func (t *JewelryTemplate) finish() {
	fmt.Println("[通用] 成品:防伪编码 + 礼盒包装\n")
}
/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Template Method Pattern  模板方法模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/4/25 10:09
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : jewelry.go
*/
package entity

// 珠宝接口:仅约束可变步骤
type Jewelry interface {
	Shaping() string // 塑形
	Inlay() string   // 镶嵌
}
/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Template Method Pattern  模板方法模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/4/25 10:09
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : ring.go
*/
package service

import "fmt"

// Ring 戒指:实现 entity.Jewelry 接口
type Ring struct{}

func NewRing() *Ring {
	return &Ring{}
}

func (r *Ring) Shaping() string {
	return fmt.Sprintf("[可变] 戒指塑形:标准戒圈成型")
}

func (r *Ring) Inlay() string {
	return fmt.Sprintf("[可变] 戒指镶嵌:单颗主石爪镶工艺")
}



/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Template Method Pattern  模板方法模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/4/25 10:10
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : necklace.go
*/
package service

import "fmt"

// Necklace 项链
type Necklace struct{}

func NewNecklace() *Necklace {
	return &Necklace{}
}

func (n *Necklace) Shaping() string {
	return fmt.Sprintf("[可变] 项链塑形:链条压制成型")
}

func (n *Necklace) Inlay() string {
	return fmt.Sprintf("[可变] 项链镶嵌:碎钻群镶点缀")
}


/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Template Method Pattern  模板方法模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/4/25 10:10
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : bracelet.go
*/
package service

import "fmt"

// Bracelet 手镯
type Bracelet struct{}

func NewBracelet() *Bracelet {
	return &Bracelet{}
}

func (b *Bracelet) Shaping() string {
	return fmt.Sprintf("[可变] 手镯塑形:宽版镯身压铸")
}

func (b *Bracelet) Inlay() string {
	return fmt.Sprintf("[可变] 手镯镶嵌:侧边排镶宝石")
}

调用:

/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Template Method Pattern  模板方法模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/4/25 10:13
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : templatemethodbll.go
templatemethod/
├── go.mod                  # 项目模块
├── internal/               # 内部包(外部不可访问)
│   ├── template/           # 模板层(算法骨架 + 通用步骤)
│   │   └── jewelry_template.go
│   ├── entity/             # 实体/接口层(定义约束)
│   │   └── jewelry.go
│   └── service/            # 业务实现层(可变步骤具体实现)
│       ├── ring.go
│       ├── necklace.go
│       └── bracelet.go
└── main.go                 # 入口调用层
*/
package bll

import (
	"fmt"
	"godesginpattern/templatemethod/service"
	"godesginpattern/templatemethod/template"
)

func TemplateMethodMain() {
	fmt.Println("=== 企业级珠宝制作系统 ===")

	// 制作戒指
	ring := service.NewRing()
	template.NewJewelryTemplate(ring).Make()

	// 制作项链
	necklace := service.NewNecklace()
	template.NewJewelryTemplate(necklace).Make()

	// 制作手镯
	bracelet := service.NewBracelet()
	template.NewJewelryTemplate(bracelet).Make()
}

输出:

image

哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)