五月天青色头像情侣网名,国产亚洲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設計模式)的評論 (共 條)

分享到微博請遵守國家法律
万年县| 东莞市| 绿春县| 阿图什市| 甘肃省| 定日县| 东乡族自治县| 崇义县| 陇南市| 金沙县| 永川市| 临清市| 法库县| 濮阳县| 富锦市| 遂昌县| 平湖市| 鹤壁市| 九台市| 林芝县| 定南县| 岳池县| 常州市| 双鸭山市| 宿松县| 东台市| 交城县| 平塘县| 淮北市| 稷山县| 衡南县| 鄯善县| 枣庄市| 常山县| 白沙| 射阳县| 体育| 青阳县| 彭水| 梅河口市| 新沂市|