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

推荐订阅源

F
Fortinet All Blogs
MyScale Blog
MyScale Blog
Microsoft Security Blog
Microsoft Security Blog
量子位
B
Blog
aimingoo的专栏
aimingoo的专栏
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog
T
The Exploit Database - CXSecurity.com
N
News | PayPal Newsroom
Cloudbric
Cloudbric
A
About on SuperTechFans
AI
AI
Hacker News: Ask HN
Hacker News: Ask HN
S
Schneier on Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 最新话题
T
The Blog of Author Tim Ferriss
Simon Willison's Weblog
Simon Willison's Weblog
有赞技术团队
有赞技术团队
H
Heimdal Security Blog
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏
D
Docker
Security Archives - TechRepublic
Security Archives - TechRepublic
N
News and Events Feed by Topic
IT之家
IT之家
Know Your Adversary
Know Your Adversary
N
Netflix TechBlog - Medium
T
Tailwind CSS Blog
B
Blog RSS Feed
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
博客园 - 叶小钗
美团技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
LangChain Blog
The Hacker News
The Hacker News
Y
Y Combinator Blog
I
Intezer
The Register - Security
The Register - Security
F
Full Disclosure
V
V2EX
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Last Week in AI
Last Week in AI
Martin Fowler
Martin Fowler

博客园 - ®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: Abstract Factory Pattern go: Model,Interface,DAL ,Factory,BLL using mysql go: Simple Factory 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: Factory Method Pattern
®Geovin Du Dream Park™ · 2026-04-12 · via 博客园 - ®Geovin Du Dream Park™

项目结构:

image

/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Factory Method Pattern  Go 工厂方法模式
# 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/12 12:16
# User      :  geovindu
# Product   : GoLand
# Project   : sudydemo
# File      : jewelry.go
*/
package factorymethod

// Jewelry 珠宝产品接口
type Jewelry interface {
	// 核心属性
	GetMaterial() string // 获取材质
	GetWeight() float64  // 获取克重
	GetGem() string      // 获取宝石

	// 统一生产流程
	Design() // 设计
	Make()   // 制作
	Check()  // 质检
	Price()  // 定价
}





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

// JewelryFactory 珠宝工厂接口
type JewelryFactory interface {
	CreateJewelry(material string, weight float64, gem string) Jewelry
}


/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Factory Method Pattern  Go 工厂方法模式
# 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/12 12:17
# User      :  geovindu
# Product   : GoLand
# Project   : sudydemo
# File      : ring.go
*/
package factorymethod

import "fmt"

// Ring 戒指(具体产品)
type Ring struct {
	material string  // 材质
	weight   float64 // 克重
	gem      string  // 宝石
}

// 实现 Jewelry 接口的核心属性
func (r *Ring) GetMaterial() string { return r.material }
func (r *Ring) GetWeight() float64  { return r.weight }
func (r *Ring) GetGem() string      { return r.gem }

// 实现 Jewelry 接口的生产流程
func (r *Ring) Design() {
	fmt.Printf("【戒指】设计:%s材质,镶嵌%s\n", r.material, r.gem)
}

// 生产
func (r *Ring) Make() {
	fmt.Printf("【戒指】制作:%.2f克,打造戒托\n", r.weight)
}

// 选择
// @pagram
func (r *Ring) Check() {
	fmt.Println("【戒指】质检:尺寸、镶嵌、抛光合格")
}

// 价格
func (r *Ring) Price() {
	price := r.weight*500.0 + 2000.0 // 简化定价公式
	fmt.Printf("【戒指】定价:%.2f 元\n\n", price)
}

// RingFactory 戒指工厂(具体工厂)
type RingFactory struct{}

// 实现工厂接口,只生产戒指
// @Param material
// @Param weight
// @Param gem
// @Return ${return_types}
func (r *RingFactory) CreateJewelry(material string, weight float64, gem string) Jewelry {
	return &Ring{
		material: material,
		weight:   weight,
		gem:      gem,
	}
}


/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Factory Method Pattern  Go 工厂方法模式
# 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/12 12:18
# User      :  geovindu
# Product   : GoLand
# Project   : sudydemo
# File      : necklace.go
*/
package factorymethod

import "fmt"

// Necklace 项链(具体产品)
type Necklace struct {
	material string
	weight   float64
	gem      string
}

// 核心属性实现
func (n *Necklace) GetMaterial() string { return n.material }
func (n *Necklace) GetWeight() float64  { return n.weight }
func (n *Necklace) GetGem() string      { return n.gem }

// 生产流程实现
func (n *Necklace) Design() {
	fmt.Printf("【项链】设计:%s材质,链条镶嵌%s\n", n.material, n.gem)
}

func (n *Necklace) Make() {
	fmt.Printf("【项链】制作:%.2f克,锻造链条+吊坠\n", n.weight)
}

func (n *Necklace) Check() {
	fmt.Println("【项链】质检:链条韧性、宝石牢固度合格")
}

func (n *Necklace) Price() {
	price := n.weight*480.0 + 1800.0
	fmt.Printf("【项链】定价:%.2f 元\n\n", price)
}

// NecklaceFactory 项链工厂
type NecklaceFactory struct{}

// 只生产项链
// @Param material
// @Param weight
// @Param gem
// @Return Necklace
func (n *NecklaceFactory) CreateJewelry(material string, weight float64, gem string) Jewelry {
	return &Necklace{
		material: material,
		weight:   weight,
		gem:      gem,
	}
}


/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Factory Method Pattern  Go 工厂方法模式
# 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/12 12:18
# User      :  geovindu
# Product   : GoLand
# Project   : sudydemo
# File      : bracelet.go
*/
package factorymethod

import "fmt"

// Bracelet 手镯(具体产品)
type Bracelet struct {
	material string
	weight   float64
	gem      string
}

// 核心属性实现
func (b *Bracelet) GetMaterial() string { return b.material }
func (b *Bracelet) GetWeight() float64  { return b.weight }
func (b *Bracelet) GetGem() string      { return b.gem }

// 生产流程实现
// @Title 生产流程实现
// @Description ${user}
// @Author geovindu ${date} ${time}
// @Param name
// @Return string
func (b *Bracelet) Design() {
	fmt.Printf("【手镯】设计:%s材质,镯身镶嵌%s\n", b.material, b.gem)
}

// @Title 生产流程实现
// @Description ${user}
// @Author geovindu ${date} ${time}
// @Param name
// @Return string
func (b *Bracelet) Make() {
	fmt.Printf("【手镯】制作:%.2f克,弯曲成型+打磨\n", b.weight)
}

// @Title 生产流程实现
// @Description ${user}
// @Author geovindu ${date} ${time}
// @Param name
// @Return string
func (b *Bracelet) Check() {
	fmt.Println("【手镯】质检:弧度、舒适度、镶嵌合格")
}

// @Title 生产流程实现
// @Description ${user}
// @Author geovindu ${date} ${time}
// @Param name
// @Return string
func (b *Bracelet) Price() {
	price := b.weight*450.0 + 1500.0
	fmt.Printf("【手镯】定价:%.2f 元\n\n", price)
}

// BraceletFactory 手镯工厂
type BraceletFactory struct{}

// 只生产手镯
// @Title 生产流程实现 手镯
// @Description ${user}
// @Author geovindu ${date} ${time}
// @Param name
// @Return string
func (b *BraceletFactory) CreateJewelry(material string, weight float64, gem string) Jewelry {
	return &Bracelet{
		material: material,
		weight:   weight,
		gem:      gem,
	}
} 

调用:

/*
# 版权所有  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/12 18:56
# User      :  geovindu
# Product   : GoLand
# Project   : sudydemo
# File      : factorymethodbll.go
*/
package bll

import (
	"fmt"
	"sudydemo/factorymethod"
)

// 统一执行珠宝生产流程
func produceJewelry(f factorymethod.JewelryFactory, material string, weight float64, gem string) {
	jewelry := f.CreateJewelry(material, weight, gem)
	jewelry.Design()
	jewelry.Make()
	jewelry.Check()
	jewelry.Price()
}

// 显示示例
func FactoryMethodMain() {

	fmt.Println("===Factory Method Pattern工厂方法模式===")
	// 1. 戒指工厂生产钻戒
	ringFactory := &factorymethod.RingFactory{}
	produceJewelry(ringFactory, "铂金", 5.8, "钻石")

	// 2. 项链工厂生产宝石项链
	necklaceFactory := &factorymethod.NecklaceFactory{}
	produceJewelry(necklaceFactory, "黄金", 12.3, "红宝石")

	// 3. 手镯工厂生产翡翠手镯
	braceletFactory := &factorymethod.BraceletFactory{}
	produceJewelry(braceletFactory, "足银", 20.5, "翡翠")
}

main():

输出::

image

/*
# 版权所有  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/18 22:37
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : jewelry.go
*/
package entity

// Jewelry 产品接口(工厂方法的 产品基类)
type Jewelry interface {
	// 生产流程
	//设计
	Design()
	//生产
	Make()
	//质检
	Check()
	//报价
	Price() float64

	// 属性
	//名称
	GetName() string
	//材质
	GetMaterial() string
	//重量
	GetWeight() float64
	//
	GetGem() string
}
/*
# 版权所有  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/18 22:37
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : factory.go
*/
package factory

import "godesginpattern/factorymethodone/app/entity"

// Factory 工厂方法核心接口
type Factory interface {
	Create(material string, weight float64, gem string) entity.Jewelry
}


/*
# 版权所有  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/18 22:38
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : ring_factory.go
*/
package factory

import (
	"fmt"
	"godesginpattern/factorymethodone/app/entity"
)

// Ring 戒指实体
type Ring struct {
	Material string
	Weight   float64
	Gem      string
}

func (r *Ring) GetName() string     { return "戒指" }
func (r *Ring) GetMaterial() string { return r.Material }
func (r *Ring) GetWeight() float64  { return r.Weight }
func (r *Ring) GetGem() string      { return r.Gem }

func (r *Ring) Design() {
	// 企业级:这里可写日志、埋点、事件...
	fmt.Printf("【戒指】设计:%s材质,镶嵌%s\n", r.Material, r.Gem)
}
func (r *Ring) Make() {
	fmt.Printf("【戒指】制作:%.2f克\n", r.Weight)

}
func (r *Ring) Check() {
	fmt.Println("【戒指】质检:尺寸、镶嵌、抛光合格")
}
func (r *Ring) Price() float64 {
	price := r.Weight*500 + 2000
	fmt.Printf("【戒指】价格:%.2f 元\n\n", price)
	return price
}

// === 工厂 ===
type RingFactory struct{}

func (r *RingFactory) Create(material string, weight float64, gem string) entity.Jewelry {
	return &Ring{
		Material: material,
		Weight:   weight,
		Gem:      gem,
	}
}


/*
# 版权所有  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/18 22:41
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : necklace_factory.go
*/
package factory

import (
	"fmt"
	"godesginpattern/factorymethodone/app/entity"
)

type Necklace struct {
	Material string
	Weight   float64
	Gem      string
}

func (n *Necklace) Design() {
	fmt.Printf("【项链】设计:%s材质,镶嵌%s\n", n.Material, n.Gem)
}
func (n *Necklace) Make() {
	fmt.Printf("【项链】制作:%.2f克\n", n.Weight)
}
func (n *Necklace) Check() {
	fmt.Println("【项链】质检:链条韧性、宝石牢固度合格")
}
func (n *Necklace) Price() float64 {
	price := n.Weight*480 + 1800
	fmt.Printf("【项链】价格:%.2f 元\n\n", price)
	return price
}

func (n *Necklace) GetName() string     { return "项链" }
func (n *Necklace) GetMaterial() string { return n.Material }
func (n *Necklace) GetWeight() float64  { return n.Weight }
func (n *Necklace) GetGem() string      { return n.Gem }

type NecklaceFactory struct{}

func (n *NecklaceFactory) Create(material string, weight float64, gem string) entity.Jewelry {
	return &Necklace{material, weight, gem}
}


/*
# 版权所有  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/18 22:41
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : bracelet_factory.go
*/
package factory

import (
	"fmt"
	"godesginpattern/factorymethodone/app/entity"
)

type Bracelet struct {
	Material string
	Weight   float64
	Gem      string
}

func (b *Bracelet) Design() {
	fmt.Printf("【手镯】设计:%s材质,镶嵌%s\n", b.Material, b.Gem)
}
func (b *Bracelet) Make() {
	fmt.Printf("【手镯】制作:%.2f克\n", b.Weight)
}
func (b *Bracelet) Check() {
	fmt.Println("【手镯】质检:弧度、舒适度、镶嵌合格")
}
func (b *Bracelet) Price() float64 {
	price := b.Weight*450 + 1500
	fmt.Printf("【手镯】价格:%.2f 元\n\n", price)
	return price
}
func (b *Bracelet) GetName() string     { return "手镯" }
func (b *Bracelet) GetMaterial() string { return b.Material }
func (b *Bracelet) GetWeight() float64  { return b.Weight }
func (b *Bracelet) GetGem() string      { return b.Gem }

type BraceletFactory struct{}

func (b *BraceletFactory) Create(material string, weight float64, gem string) entity.Jewelry {
	return &Bracelet{material, weight, gem}
}
/*
# 版权所有  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/18 22:42
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : jewelry_service.go
*/
package service

import (
	"godesginpattern/factorymethodone/app/entity"
	"godesginpattern/factorymethodone/factory"
)

type JewelryService struct{}

// Produce 统一生产流程
func (s *JewelryService) Produce(f factory.Factory, material string, weight float64, gem string) entity.Jewelry {
	// 工厂创建产品
	j := f.Create(material, weight, gem)

	// 标准业务流程
	j.Design()
	j.Make()
	j.Check()
	j.Price()

	return 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/18 22:42
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : jewelry_api.go
*/
package api

import (
	"godesginpattern/factorymethodone/app/entity"
	"godesginpattern/factorymethodone/factory"
	"godesginpattern/factorymethodone/service"
)

type JewelryAPI struct {
	Service *service.JewelryService
}

func NewJewelryAPI() *JewelryAPI {
	return &JewelryAPI{
		Service: &service.JewelryService{},
	}
}

// 生产戒指
func (j *JewelryAPI) MakeRing(material string, weight float64, gem string) entity.Jewelry {
	return j.Service.Produce(&factory.RingFactory{}, material, weight, gem)
}

// 生产项链
func (j *JewelryAPI) MakeNecklace(material string, weight float64, gem string) entity.Jewelry {
	return j.Service.Produce(&factory.NecklaceFactory{}, material, weight, gem)
}

// 生产手镯
func (j *JewelryAPI) MakeBracelet(material string, weight float64, gem string) entity.Jewelry {
	return j.Service.Produce(&factory.BraceletFactory{}, material, weight, gem)
}
/*
# 版权所有  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/12 18:56
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : factorymethodbll.go
jewelry-app/
├── go.mod            // 模块文件(自动生成)
├── main.go           // 程序入口(调用包)
└── jewelry/          // 珠宝工厂包(全部封装在这里)

	├── jewelry.go    // 产品接口
	├── factory.go    // 工厂接口
	├── ring.go       // 戒指产品+工厂
	├── necklace.go   // 项链产品+工厂
	└── bracelet.go   // 手镯产品+工厂

2.
jewelry-app/
├── go.mod
├── main.go                     // 入口(路由/启动)
├── app/
│   └── entity/                 // 实体层(模型定义)
│       └── jewelry.go          // 珠宝接口 & 模型
├── factory/                    // 工厂层(核心:工厂方法)
│   ├── factory.go              // 工厂接口
│   ├── ring_factory.go         // 戒指工厂
│   ├── necklace_factory.go     // 项链工厂
│   └── bracelet_factory.go     // 手镯工厂
├── service/                    // 业务逻辑层(Service)
│   └── jewelry_service.go      // 统一生产服务
└── api/                        // 接口层(对外提供调用)

	└── jewelry_api.go
*/

package bll

import (
	"fmt"
	"godesginpattern/factorymethodone/api"
)

func FactoryMethodMain() {
	// 初始化接口层
	jAPI := api.NewJewelryAPI()

	// 生产钻戒
	ring := jAPI.MakeRing("铂金", 5.8, "钻石")
	fmt.Printf("生产 %s 成功,价格:%.2f\n", ring.GetName(), ring.Price())

	// 生产项链
	necklace := jAPI.MakeNecklace("黄金", 12.3, "红宝石")
	fmt.Printf("生产 %s 成功,价格:%.2f\n", necklace.GetName(), necklace.Price())

	// 生产手镯
	bracelet := jAPI.MakeBracelet("足银", 20.5, "翡翠")
	fmt.Printf("生产 %s 成功,价格:%.2f\n", bracelet.GetName(), bracelet.Price())
}

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