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

推荐订阅源

U
Unit 42
N
News and Events Feed by Topic
S
Schneier on Security
G
GRAHAM CLULEY
Scott Helme
Scott Helme
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
C
CERT Recently Published Vulnerability Notes
T
The Exploit Database - CXSecurity.com
C
Cisco Blogs
T
The Blog of Author Tim Ferriss
Cisco Talos Blog
Cisco Talos Blog
P
Privacy & Cybersecurity Law Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 司徒正美
Blog — PlanetScale
Blog — PlanetScale
Project Zero
Project Zero
MyScale Blog
MyScale Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
The Last Watchdog
The Last Watchdog
Vercel News
Vercel News
The Cloudflare Blog
C
Check Point Blog
Help Net Security
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
Stack Overflow Blog
Stack Overflow Blog
腾讯CDC
NISL@THU
NISL@THU
S
Security @ Cisco Blogs
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
S
SegmentFault 最新的问题
MongoDB | Blog
MongoDB | Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
AWS News Blog
AWS News Blog
Cloudbric
Cloudbric
N
News and Events Feed by Topic
PCI Perspectives
PCI Perspectives
S
Securelist
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
Vulnerabilities – Threatpost
S
Secure Thoughts

博客园 - ®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: 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: 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: Prototype Pattern
®Geovin Du D · 2026-04-19 · via 博客园 - ®Geovin Du Dream Park™
/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Prototype 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/18 21:48
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : jewelry_model.go
*/
package model

// JewelryModel 珠宝数据模型
type JewelryModel struct {
	// 基础属性(原型复用)
	Material   string  // 材质
	GoldWeight float64 // 金重
	StoneType  string  // 主石
	StoneCarat float64 // 克拉
	Craft      string  // 工艺
	BasePrice  float64 // 基础价

	// 定制属性
	CertNo    string // 证书号
	Engraving string // 刻字
	CustomID  string // 定制单号
}
/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Prototype 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/18 21:49
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : jewelry.go
*/
package prototype

import "godesginpattern/prototype/model"

// Prototype 原型接口
type Prototype interface {
	Clone() Prototype
}

// JewelryPrototype 珠宝原型
type JewelryPrototype struct {
	Data model.JewelryModel // 依赖模型
}

// Clone 克隆方法(深拷贝)
func (j *JewelryPrototype) Clone() Prototype {
	return &JewelryPrototype{
		Data: j.Data, // Go 值拷贝 = 深拷贝
	}
}

// Customize 定制方法
func (j *JewelryPrototype) Customize(certNo, engraving string) {
	j.Data.CertNo = certNo
	j.Data.Engraving = engraving
	j.Data.CustomID = "CUST_" + certNo
}
/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Prototype 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/18 21:49
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : prototype_builder.go
*/
package builder

import (
	"godesginpattern/prototype/model"
	"godesginpattern/prototype/prototype"
)

// NewClassicDiamondRing 经典六爪钻戒原型
func NewClassicDiamondRing() *prototype.JewelryPrototype {
	return &prototype.JewelryPrototype{
		Data: model.JewelryModel{
			Material:   "PT950铂金",
			GoldWeight: 3.2,
			StoneType:  "天然钻石",
			StoneCarat: 0.5,
			Craft:      "六爪镶+高抛光",
			BasePrice:  12999.00,
		},
	}
}

// NewGoldBangle 足金手镯原型
func NewGoldBangle() *prototype.JewelryPrototype {
	return &prototype.JewelryPrototype{
		Data: model.JewelryModel{
			Material:   "足金999",
			GoldWeight: 20.5,
			StoneType:  "无宝石",
			StoneCarat: 0,
			Craft:      "哑光磨砂",
			BasePrice:  8999.00,
		},
	}
}
/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Prototype 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/18 21:49
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : customize_service.go
*/
package service

import (
	"fmt"
	"godesginpattern/prototype/prototype"
)

// CustomizeService 定制服务
type CustomizeService struct{}

// CreateCustomJewelry 克隆原型并生成定制珠宝
func (s *CustomizeService) CreateCustomJewelry(
	proto *prototype.JewelryPrototype,
	certNo, engraving string,
) *prototype.JewelryPrototype {
	// 克隆
	customObj := proto.Clone().(*prototype.JewelryPrototype)
	// 定制
	customObj.Customize(certNo, engraving)
	return customObj
}

// ShowInfo 打印详情
func (s *CustomizeService) ShowInfo(j *prototype.JewelryPrototype) {
	m := j.Data
	fmt.Printf("=== 定制珠宝信息 ===\n")
	fmt.Printf("材质:%s | 金重:%.2fg | 主石:%s(%.2fct)\n", m.Material, m.GoldWeight, m.StoneType, m.StoneCarat)
	fmt.Printf("工艺:%s | 基础价:%.2f\n", m.Craft, m.BasePrice)
	fmt.Printf("证书号:%s | 刻字:%s | 单号:%s\n", m.CertNo, m.Engraving, m.CustomID)
	fmt.Println("---------------------------")
} 

调用:

/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Prototype 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/18 21:52
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : prototypebll.go
真正企业级结构化、严格分层、职责单一、完全可扩展
结构化 + 分层清晰 + 职责单一 + 易扩展
✅ 结构化
严格按照企业级 Go 项目结构分层
✅ 分层明确
model:数据
prototype:克隆
builder:造原型
service:业务服务
cmd:入口
✅ 职责单一
每层只做一件事,互不干扰
✅ 极易扩展
新增珠宝款式:只加 builder
新增属性:只改 model
新增服务:只加 service
新增克隆类型:只加 prototype
✅ 适合生产环境
无冗余、无耦合、可维护、可测试、可文档化
Prototype/
├── go.mod                    // 项目模块
├── cmd/
│   └── main.go               // 系统入口(仅启动,无业务)
├── internal/
│   ├── prototype/            // 原型层:定义可克隆对象(核心)
│   │   └── jewelry.go
│   ├── builder/              // 构建层:创建基础原型(职责单一)
│   │   └── prototype_builder.go
│   ├── service/              // 服务层:批量定制业务逻辑
│   │   └── customize_service.go
│   └── model/                // 模型层:纯数据结构
│       └── jewelry_model.go
└── README.md                 // 架构说明
*/
package bll

import (
	"godesginpattern/prototype/builder"
	"godesginpattern/prototype/service"
)

func PrototypeMain() {
	// 初始化服务
	customService := &service.CustomizeService{}

	// 创建基础原型
	ringProto := builder.NewClassicDiamondRing()
	bangleProto := builder.NewGoldBangle()

	// 批量定制
	ring1 := customService.CreateCustomJewelry(ringProto, "GIA1001", "一生一世·张三")
	ring2 := customService.CreateCustomJewelry(ringProto, "GIA1002", "执子之手·李四")
	bangle1 := customService.CreateCustomJewelry(bangleProto, "NGTC2001", "平安喜乐·王五")

	// 输出
	customService.ShowInfo(ring1)
	customService.ShowInfo(ring2)
	customService.ShowInfo(bangle1)
} 

输出:

image

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