无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

12-抽象工廠方法模式(Easy搞定Golang設(shè)計(jì)模式)

2023-06-18 22:37 作者:吃饅頭啊啊啊  | 我要投稿

package main


import "fmt"


type CPU interface {

Calculate()

}


type GPU interface {

Display()

}


type Memory interface {

Storage()

}


type VendorFactory interface {

VendorCPU()

VendorGPU()

VendorMemory()

}


type IntelCPU struct {

}


func (ic *IntelCPU) Calculate() {

fmt.Println("Intel Cpu Calculating...")

}


type IntelGPU struct {

}


func (ig *IntelGPU) Display() {

fmt.Println("Intel Gpu Displaying...")

}


type IntelMemory struct {

}


func (im *IntelMemory) Storage() {

fmt.Println("Intel Memory Storage...")

}


type IntelFactory struct {

}


func (ifac *IntelFactory) VendorCPU() CPU {

return &IntelCPU{}

}


func (ifac *IntelFactory) VendorGPU() GPU {

return &IntelGPU{}

}


func (ifac *IntelFactory) VendorMemory() Memory {

return &IntelMemory{}

}


type NvidiaCPU struct {

}


func (nc *NvidiaCPU) Calculate() {

fmt.Println("Nvidia Cpu Calculating...")

}


type NvidiaGPU struct {

}


func (nv *NvidiaGPU) Display() {

fmt.Println("Nvidia Gpu Displaying...")

}


type NvidiaMemory struct {

}


func (im *NvidiaMemory) Storage() {

fmt.Println("Nvidia Memory Storage...")

}


type NvidiaFactory struct {

}


func (ifac *NvidiaFactory) VendorCPU() CPU {

return &NvidiaCPU{}

}


func (ifac *NvidiaFactory) VendorGPU() GPU {

return &NvidiaGPU{}

}


func (ifac *NvidiaFactory) VendorMemory() Memory {

return &NvidiaMemory{}

}


type KingstonCPU struct {

}


func (ic *KingstonCPU) Calculate() {

fmt.Println("Kingston Cpu Calculating...")

}


type KingstonGPU struct {

}


func (ig *KingstonGPU) Display() {

fmt.Println("Kingston Gpu Displaying...")

}


type KingstonMemory struct {

}


func (im *KingstonMemory) Storage() {

fmt.Println("Kingston Memory Storage...")

}


type KingstonFactory struct {

}


func (ifac *KingstonFactory) VendorCPU() CPU {

return &IntelCPU{}

}


func (ifac *KingstonFactory) VendorGPU() GPU {

return &IntelGPU{}

}


func (ifac *KingstonFactory) VendorMemory() Memory {

return &IntelMemory{}

}


func main() {


intel := IntelFactory{}

nvidia := NvidiaFactory{}

kingston := KingstonFactory{}


fmt.Println("Install first pc:")

intel.VendorCPU().Calculate()

intel.VendorGPU().Display()

intel.VendorMemory().Storage()


fmt.Println("Install second pc:")

intel.VendorCPU().Calculate()

nvidia.VendorGPU().Display()

kingston.VendorMemory().Storage()

}

12-抽象工廠方法模式(Easy搞定Golang設(shè)計(jì)模式)的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
内黄县| 美姑县| 壶关县| 石门县| 弋阳县| 海阳市| 平利县| 上犹县| 宣武区| 永胜县| 青阳县| 宜兰市| 海丰县| 农安县| 晋宁县| 休宁县| 合作市| 招远市| 阳新县| 唐山市| 濮阳市| 广宁县| 深水埗区| 万载县| 白银市| 响水县| 贡觉县| 龙井市| 九龙县| 正镶白旗| 枣庄市| 乐业县| 囊谦县| 灯塔市| 开封市| 中山市| 吉水县| 鄢陵县| 潜江市| 上林县| 贺州市|