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

推荐订阅源

B
Blog
Blog — PlanetScale
Blog — PlanetScale
酷 壳 – CoolShell
酷 壳 – CoolShell
GbyAI
GbyAI
M
MIT News - Artificial intelligence
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
C
Check Point Blog
云风的 BLOG
云风的 BLOG
aimingoo的专栏
aimingoo的专栏
V
Visual Studio Blog
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
Spread Privacy
Spread Privacy
博客园 - Franky
Vercel News
Vercel News
月光博客
月光博客
罗磊的独立博客
博客园 - 叶小钗
腾讯CDC
A
About on SuperTechFans
P
Privacy International News Feed
V
V2EX
L
LINUX DO - 最新话题
K
Kaspersky official blog
P
Privacy & Cybersecurity Law Blog
D
DataBreaches.Net
D
Darknet – Hacking Tools, Hacker News & Cyber Security
有赞技术团队
有赞技术团队
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Stack Overflow Blog
Stack Overflow Blog
T
Tor Project blog
MyScale Blog
MyScale Blog
Y
Y Combinator Blog
G
GRAHAM CLULEY
V
Vulnerabilities – Threatpost
Recorded Future
Recorded Future
大猫的无限游戏
大猫的无限游戏
P
Proofpoint News Feed
L
LangChain Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
雷峰网
雷峰网
Project Zero
Project Zero
G
Google Developers Blog
博客园 - 【当耐特】
C
Cisco Blogs
Cisco Talos Blog
Cisco Talos Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
The GitHub Blog
The GitHub Blog

博客园 - ®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:Template Method Pattern go: Strategy 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: Visitor Pattern
®Geovin Du Dream Park™ · 2026-04-23 · via 博客园 - ®Geovin Du Dream Park™

项目结构:

image

/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Visitor 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/23 20:16
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : jewelry.go
*/
package domain

// Jewel 珠宝接口
// 这里只定义 Accept,不引用任何 Visitor 接口
type Jewel interface {
	Accept(v any)
}

// Diamond 钻石
type Diamond struct {
	Carat         float64
	Clarity       string
	PricePerCarat float64
}

func (d *Diamond) Accept(v any) {
	// 由 visitor 内部断言处理
}

// Gold 黄金
type Gold struct {
	Weight       float64
	Purity       string
	PricePerGram float64
}

func (g *Gold) Accept(v any) {}

// Jade 翡翠
type Jade struct {
	Color     string
	Texture   string
	BasePrice float64
}

func (j *Jade) Accept(v any) {}
/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Visitor 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/23 20:17
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : cleaner.go
*/
package visitor

import (
	"fmt"
	"godesginpattern/visitordesgin/domain"
)

// Cleaner 清洁师
type Cleaner struct{}

func NewCleaner() *Cleaner {
	return &Cleaner{}
}

func (c *Cleaner) VisitDiamond(d *domain.Diamond) {
	fmt.Println("[清洁] 钻石:超声波深度去污")
}

func (c *Cleaner) VisitGold(g *domain.Gold) {
	fmt.Println("[清洁] 黄金:酸洗抛光提亮")
}

func (c *Cleaner) VisitJade(j *domain.Jade) {
	fmt.Println("[清洁] 翡翠:软布+温水养护")
}



/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Visitor 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/23 20:17
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : identifier.go
*/
package visitor

import (
	"fmt"
	"godesginpattern/visitordesgin/domain"
)

// Identifier 鉴定师
type Identifier struct{}

func NewIdentifier() *Identifier {
	return &Identifier{}
}

func (i *Identifier) VisitDiamond(d *domain.Diamond) {
	fmt.Printf("[鉴定] 钻石净度 %s -> 优质天然钻\n", d.Clarity)
}

func (i *Identifier) VisitGold(g *domain.Gold) {
	fmt.Printf("[鉴定] 黄金纯度 %s -> 高纯度足金\n", g.Purity)
}

func (i *Identifier) VisitJade(j *domain.Jade) {
	fmt.Printf("[鉴定] 翡翠 %s/%s -> 天然A货\n", j.Color, j.Texture)
}


/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Visitor 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/23 20:17
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : iface.go
*/
package visitor

import "godesginpattern/visitordesgin/domain"

// Visitor 接口 放在 visitor 包内
// 单向依赖 domain,无循环
type Visitor interface {
	VisitDiamond(d *domain.Diamond)
	VisitGold(g *domain.Gold)
	VisitJade(j *domain.Jade)
}


/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Visitor 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/23 20:17
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : valuator.go
*/
package visitor

import (
	"fmt"
	"godesginpattern/visitordesgin/domain"
)

// Valuator 估值师
type Valuator struct{}

func NewValuator() *Valuator {
	return &Valuator{}
}

// VisitDiamond 钻石估值
func (v *Valuator) VisitDiamond(d *domain.Diamond) {
	total := d.Carat * d.PricePerCarat
	fmt.Printf("[估值] 钻石 %.2f克拉 | 总价: %.2f\n", d.Carat, total)
}

// VisitGold 黄金估值
func (v *Valuator) VisitGold(g *domain.Gold) {
	total := g.Weight * g.PricePerGram
	fmt.Printf("[估值] 黄金 %.2fg | 总价: %.2f\n", g.Weight, total)
}

// VisitJade 翡翠估值
func (v *Valuator) VisitJade(j *domain.Jade) {
	fmt.Printf("[估值] 翡翠 %s/%s | 评估价: %.2f\n", j.Color, j.Texture, j.BasePrice)
}
/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Visitor 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/23 20:17
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : collection.go
*/
package structure

import (
	"godesginpattern/visitordesgin/domain"
	"godesginpattern/visitordesgin/visitor"
)

// JewelCollection 珠宝集合
type JewelCollection struct {
	jewels []domain.Jewel
}

func NewJewelCollection() *JewelCollection {
	return &JewelCollection{
		jewels: make([]domain.Jewel, 0),
	}
}

// Add 添加珠宝
func (c *JewelCollection) Add(j domain.Jewel) {
	c.jewels = append(c.jewels, j)
}

// Accept 访问者处理所有珠宝
func (c *JewelCollection) Accept(v visitor.Visitor) {
	for _, item := range c.jewels {
		switch j := item.(type) {
		case *domain.Diamond:
			v.VisitDiamond(j)
		case *domain.Gold:
			v.VisitGold(j)
		case *domain.Jade:
			v.VisitJade(j)
		}
	}
}

调用:

/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:
# 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/23 20:36
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : visitorbll.go
*/
package bll

import (
	"fmt"
	"godesginpattern/visitordesgin/domain"
	"godesginpattern/visitordesgin/structure"
	"godesginpattern/visitordesgin/visitor"
)

func VisitorMain() {
	// 1. 创建珠宝
	diamond := &domain.Diamond{Carat: 1.5, Clarity: "VVS1", PricePerCarat: 80000}
	gold := &domain.Gold{Weight: 20, Purity: "9999", PricePerGram: 600}
	jade := &domain.Jade{Color: "帝王绿", Texture: "玻璃种", BasePrice: 180000}

	// 2. 创建集合
	coll := structure.NewJewelCollection()
	coll.Add(diamond)
	coll.Add(gold)
	coll.Add(jade)

	// 3. 执行访问者(统一用 fmt 保证输出顺序正确)
	fmt.Println("=== 估值师 ===")
	coll.Accept(visitor.NewValuator())

	fmt.Println("\n=== 鉴定师 ===")
	coll.Accept(visitor.NewIdentifier())

	fmt.Println("\n=== 清洁师 ===")
	coll.Accept(visitor.NewCleaner())
}

输出:

image

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