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

推荐订阅源

The GitHub Blog
The GitHub Blog
K
Kaspersky official blog
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
U
Unit 42
D
Docker
I
InfoQ
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
C
Check Point Blog
The Cloudflare Blog
美团技术团队
V
Vulnerabilities – Threatpost
博客园_首页
T
Threat Research - Cisco Blogs
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
A
Arctic Wolf
IT之家
IT之家
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
Troy Hunt's Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
人人都是产品经理
人人都是产品经理
C
Cyber Attacks, Cyber Crime and Cyber Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Archives - TechRepublic
Security Archives - TechRepublic
S
Schneier on Security
Apple Machine Learning Research
Apple Machine Learning Research
MyScale Blog
MyScale Blog
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
The Blog of Author Tim Ferriss
GbyAI
GbyAI
The Last Watchdog
The Last Watchdog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
The Register - Security
The Register - Security
博客园 - 三生石上(FineUI控件)
Forbes - Security
Forbes - Security
NISL@THU
NISL@THU
Y
Y Combinator Blog
T
Threatpost
Microsoft Azure Blog
Microsoft Azure Blog
L
Lohrmann on Cybersecurity

博客园 - ®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: Prototype Pattern go: Bridge Pattern go: Adapter Pattern go: Builder Pattern 密码进行加盐哈希 using CSharp,Python,Go,Java 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: Abstract Factory Pattern
®Geovin Du Dream Park™ · 2026-04-16 · via 博客园 - ®Geovin Du Dream Park™

项目结构:

image

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

// JewelryBase 所有珠宝的基础属性
type JewelryBase struct {
	Material string  // 材质
	Weight   float64 // 重量(克)
	Purity   float64 // 纯度(%)
}

// Ring 戒指产品接口
type Ring interface {
	Produce() string
	CalculateCost() float64
	QualityCheck() string
	GetInfo() JewelryBase
}

// Necklace 项链产品接口
type Necklace interface {
	Produce() string
	CalculateCost() float64
	QualityCheck() string
	GetInfo() JewelryBase
}

// Earring 耳环产品接口
type Earring interface {
	Produce() string
	CalculateCost() float64
	QualityCheck() string
	GetInfo() JewelryBase
}


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

// CartierRing 卡地亚戒指
type CartierRing struct {
	base JewelryBase
}

func NewCartierRing() Ring {
	return &CartierRing{
		base: JewelryBase{Material: "18K金+钻石", Weight: 8, Purity: 0.75},
	}
}

func (c *CartierRing) Produce() string {
	return "18K金底座+钻石镶嵌工艺"
}
func (c *CartierRing) CalculateCost() float64 {
	return c.base.Weight*500*c.base.Purity + 2000
}
func (c *CartierRing) QualityCheck() string {
	return "18K金纯度≥75%,钻石无瑕疵,合格"
}
func (c *CartierRing) GetInfo() JewelryBase {
	return c.base
}

// CartierNecklace 卡地亚项链
type CartierNecklace struct {
	base JewelryBase
}

func NewCartierNecklace() Necklace {
	return &CartierNecklace{
		base: JewelryBase{Material: "18K金+钻石", Weight: 15, Purity: 0.75},
	}
}

func (c *CartierNecklace) Produce() string {
	return "18K金链条+钻石吊坠工艺"
}
func (c *CartierNecklace) CalculateCost() float64 {
	return c.base.Weight*500*c.base.Purity + 3000
}
func (c *CartierNecklace) QualityCheck() string {
	return "链条无变形,钻石镶嵌牢固,合格"
}
func (c *CartierNecklace) GetInfo() JewelryBase {
	return c.base
}

// CartierEarring 卡地亚耳环
type CartierEarring struct {
	base JewelryBase
}

func NewCartierEarring() Earring {
	return &CartierEarring{
		base: JewelryBase{Material: "18K金+钻石", Weight: 5, Purity: 0.75},
	}
}

func (c *CartierEarring) Produce() string {
	return "18K金耳针+钻石装饰工艺"
}
func (c *CartierEarring) CalculateCost() float64 {
	return c.base.Weight*500*c.base.Purity + 1500
}
func (c *CartierEarring) QualityCheck() string {
	return "佩戴舒适,钻石无脱落风险,合格"
}
func (c *CartierEarring) GetInfo() JewelryBase {
	return c.base
}


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

// TiffanyRing 蒂芙尼戒指
type TiffanyRing struct {
	base JewelryBase
}

func NewTiffanyRing() Ring {
	return &TiffanyRing{
		base: JewelryBase{Material: "铂金+蓝宝石", Weight: 7, Purity: 0.95},
	}
}

func (t *TiffanyRing) Produce() string {
	return "铂金底座+蓝宝石镶嵌工艺"
}
func (t *TiffanyRing) CalculateCost() float64 {
	return t.base.Weight*800*t.base.Purity + 2500
}
func (t *TiffanyRing) QualityCheck() string {
	return "铂金纯度≥95%,蓝宝石无裂纹,合格"
}
func (t *TiffanyRing) GetInfo() JewelryBase {
	return t.base
}

// TiffanyNecklace 蒂芙尼项链
type TiffanyNecklace struct {
	base JewelryBase
}

func NewTiffanyNecklace() Necklace {
	return &TiffanyNecklace{
		base: JewelryBase{Material: "铂金+蓝宝石", Weight: 14, Purity: 0.95},
	}
}

func (t *TiffanyNecklace) Produce() string {
	return "铂金链条+蓝宝石吊坠工艺"
}
func (t *TiffanyNecklace) CalculateCost() float64 {
	return t.base.Weight*800*t.base.Purity + 3500
}
func (t *TiffanyNecklace) QualityCheck() string {
	return "抛光达标,蓝宝石颜色均匀,合格"
}
func (t *TiffanyNecklace) GetInfo() JewelryBase {
	return t.base
}

// TiffanyEarring 蒂芙尼耳环
type TiffanyEarring struct {
	base JewelryBase
}

func NewTiffanyEarring() Earring {
	return &TiffanyEarring{
		base: JewelryBase{Material: "铂金+蓝宝石", Weight: 4, Purity: 0.95},
	}
}

func (t *TiffanyEarring) Produce() string {
	return "铂金耳针+蓝宝石装饰工艺"
}
func (t *TiffanyEarring) CalculateCost() float64 {
	return t.base.Weight*800*t.base.Purity + 1800
}
func (t *TiffanyEarring) QualityCheck() string {
	return "材质无过敏,镶嵌工艺达标,合格"
}
func (t *TiffanyEarring) GetInfo() JewelryBase {
	return t.base
}
/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Abstract Factory 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/16 21:57
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : factory.go
*/
package factory

import "godesginpattern/abstractfactory/product"

// JewelryFactory 抽象工厂:品牌生产线标准
type JewelryFactory interface {
	CreateRing() product.Ring
	CreateNecklace() product.Necklace
	CreateEarring() product.Earring
}


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

import "godesginpattern/abstractfactory/product"

// CartierFactory 卡地亚具体工厂
type CartierFactory struct{}

func (c *CartierFactory) CreateRing() product.Ring {
	return product.NewCartierRing()
}

func (c *CartierFactory) CreateNecklace() product.Necklace {
	return product.NewCartierNecklace()
}

func (c *CartierFactory) CreateEarring() product.Earring {
	return product.NewCartierEarring()
}


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

import "godesginpattern/abstractfactory/product"

// TiffanyFactory 蒂芙尼具体工厂
type TiffanyFactory struct{}

func (t *TiffanyFactory) CreateRing() product.Ring {
	return product.NewTiffanyRing()
}

func (t *TiffanyFactory) CreateNecklace() product.Necklace {
	return product.NewTiffanyNecklace()
}

func (t *TiffanyFactory) CreateEarring() product.Earring {
	return product.NewTiffanyEarring()
}
/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:  Abstract Factory 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/16 21:58
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : production.go
*/
package service

import (
	"fmt"
	"godesginpattern/abstractfactory/factory"
)

// JewelryProductionLine 统一生产线:生产 → 算成本 → 质检
func JewelryProductionLine(f factory.JewelryFactory, brandName string) {
	fmt.Printf("========== %s 珠宝生产线 ==========\n", brandName)

	// 戒指
	ring := f.CreateRing()
	fmt.Printf("\n【%s戒指】\n生产:%s\n成本:%.2f 元\n质检:%s\n",
		brandName, ring.Produce(), ring.CalculateCost(), ring.QualityCheck())

	// 项链
	necklace := f.CreateNecklace()
	fmt.Printf("\n【%s项链】\n生产:%s\n成本:%.2f 元\n质检:%s\n",
		brandName, necklace.Produce(), necklace.CalculateCost(), necklace.QualityCheck())

	// 耳环
	earring := f.CreateEarring()
	fmt.Printf("\n【%s耳环】\n生产:%s\n成本:%.2f 元\n质检:%s\n",
		brandName, earring.Produce(), earring.CalculateCost(), earring.QualityCheck())

	fmt.Println("====================================\n")
}

调用:

/*
# 版权所有  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/16 22:04
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : abstractfactorybll.go
*/
package bll

import (
	"godesginpattern/abstractfactory/factory"
	"godesginpattern/abstractfactory/service"
)

// 显示示例
func AbstractFactoryMain() {
	// 卡地亚生产线
	cartierFactory := &factory.CartierFactory{}
	service.JewelryProductionLine(cartierFactory, "卡地亚")

	// 蒂芙尼生产线
	tiffanyFactory := &factory.TiffanyFactory{}
	service.JewelryProductionLine(tiffanyFactory, "蒂芙尼")
}

输出:

image

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