五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

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

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

2022-10-08 17:08 作者:隨風的葉子  | 我要投稿
package main

// ---- 抽象層 ----

type GPU interface {
   Display()
}
type MemoryBank interface {
   Storage()
}
type CPU interface {
   Calculate()
}

type AbstractComputerFactory interface {
   CreateGPU() GPU
   CreateMemoryBank() MemoryBank
   CreateCPU() CPU
}

// ---- 實現(xiàn)層 ----

// Inter

type InterGPU struct {
}

func (t *InterGPU) Display() {
   println("Inter生產(chǎn)的顯卡:開始display")
}

type InterMemoryBank struct {
}

func (t *InterMemoryBank) Storage() {
   println("Inter生產(chǎn)的內(nèi)存:開始storage")
}

type InterCPU struct {
}

func (t *InterCPU) Calculate() {
   println("Inter生產(chǎn)的CPU:開始calculate")
}

type InterFactory struct {
}

func (t *InterFactory) CreateGPU() GPU {
   return new(InterGPU)
}
func (t *InterFactory) CreateMemoryBank() MemoryBank {
   return new(InterMemoryBank)
}
func (t *InterFactory) CreateCPU() CPU {
   return new(InterCPU)
}

// Nvidia

type NvidiaGPU struct {
}

func (t *NvidiaGPU) Display() {
   println("Nvidia生產(chǎn)的顯卡:開始display")
}

type NvidiaMemoryBank struct {
}

func (t *NvidiaMemoryBank) Storage() {
   println("Nvidia生產(chǎn)的內(nèi)存:開始storage")
}

type NvidiaCPU struct {
}

func (t *NvidiaCPU) Calculate() {
   println("Nvidia生產(chǎn)的CPU:開始calculate")
}

type NvidiaFactory struct {
}

func (t *NvidiaFactory) CreateGPU() GPU {
   return new(NvidiaGPU)
}
func (t *NvidiaFactory) CreateMemoryBank() MemoryBank {
   return new(NvidiaMemoryBank)
}
func (t *NvidiaFactory) CreateCPU() CPU {
   return new(NvidiaCPU)
}

// Kingston

type KingstonGPU struct {
}

func (t *KingstonGPU) Display() {
   println("Kingston生產(chǎn)的顯卡:開始display")
}

type KingstonMemoryBank struct {
}

func (t *KingstonMemoryBank) Storage() {
   println("Kingston生產(chǎn)的內(nèi)存:開始storage")
}

type KingstonCPU struct {
}

func (t *KingstonCPU) Calculate() {
   println("Kingston生產(chǎn)的CPU:開始calculate")
}

type KingstonFactory struct {
}

func (t *KingstonFactory) CreateGPU() GPU {
   return new(KingstonGPU)
}
func (t *KingstonFactory) CreateMemoryBank() MemoryBank {
   return new(KingstonMemoryBank)
}
func (t *KingstonFactory) CreateCPU() CPU {
   return new(KingstonCPU)
}

//組裝電腦

type Computer struct {
   gpu        GPU
   memoryBank MemoryBank
   cpu        CPU
}

func (c *Computer) ShowComputer() {
   println("----", "電腦配置", "----")
   c.gpu.Display()
   c.memoryBank.Storage()
   c.cpu.Calculate()
   println()
}

func NewComputer(gpu GPU, memoryBank MemoryBank, cpu CPU) *Computer {
   return &Computer{gpu: gpu, memoryBank: memoryBank, cpu: cpu}
}

//業(yè)務邏輯層
func main() {
   interFac := new(InterFactory)
   nvidiaFac := new(NvidiaFactory)
   kingstonFac := new(KingstonFactory)
   //第一臺電腦
   NewComputer(interFac.CreateGPU(), interFac.CreateMemoryBank(), interFac.CreateCPU()).ShowComputer()
   //第二臺電腦
   NewComputer(nvidiaFac.CreateGPU(), kingstonFac.CreateMemoryBank(), interFac.CreateCPU()).ShowComputer()
}


12-抽象工廠方法模式(Easy搞定Golang設計模式)的評論 (共 條)

分享到微博請遵守國家法律
吉木萨尔县| 甘谷县| 芜湖市| 乡城县| 开阳县| 边坝县| 芷江| 临沧市| 鞍山市| 军事| 平南县| 襄城县| 稷山县| 毕节市| 上杭县| 佛教| 满洲里市| 景泰县| 兴宁市| 奉化市| 库尔勒市| 高青县| 哈密市| 陈巴尔虎旗| 英吉沙县| 台南市| 东至县| 武功县| 武夷山市| 凤庆县| 镇坪县| 南通市| 佛冈县| 黄龙县| 兴城市| 博罗县| 望江县| 郯城县| 隆昌县| 叶城县| 屏边|