当前位置: 首页 > news >正文

首都之窗门户网站首页深圳网站建设 手机网站建设

首都之窗门户网站首页,深圳网站建设 手机网站建设,卖信息的网站,展馆设计说明范文文章目录 1. 概述1.1 角色1.2 类图 2. 代码示例2.1 设计2.2 代码2.3 类图 1. 概述 1.1 角色 AbstractFactory(抽象工厂):它声明了一组用于创建产品的方法,每一个方法对应一种产品。ConcreteFactory(具体工厂&#xf…

文章目录

  • 1. 概述
    • 1.1 角色
    • 1.2 类图
  • 2. 代码示例
    • 2.1 设计
    • 2.2 代码
    • 2.3 类图

1. 概述

1.1 角色

  • AbstractFactory(抽象工厂):它声明了一组用于创建产品的方法,每一个方法对应一种产品。
  • ConcreteFactory(具体工厂):它实现了在抽象工厂中声明的创建产品的方法,生成一组具体产品,这些产品构成了一个产品族,每一个产品都位于某个产品等级结构中。
  • AbstractProduct(抽象产品):它为每种产品声明接口,在抽象产品中声明了产品所具有的业务方法。
  • ConcreteProduct(具体产品):它定义具体工厂生产的具体产品对象,实现抽象产品接口中声明的业务方法。

1.2 类图

«interface»
ProductA
ProductA1
ProductA2
«interface»
ProductB
ProductB1
ProductB2
Client
«interface»
AbstractFactory
+CreateProductA() : ProductA
+CreateProductB() : ProductB
ConcreteFactory1
+CreateProductA() : ProductA
+CreateProductB() : ProductB
ConcreteFactory2
+CreateProductA() : ProductA
+CreateProductB() : ProductB

2. 代码示例

2.1 设计

  • 定义抽象产品A
    • 定义具体产品A-1
      • 它有NameWeight两个成员
      • 它的SetName()SetWeight()两个方法分别负责设置以上两个成员
      • 它的Get()方法获取它本身的信息
    • 定义具体产品A-2
      • 它有NameWeight两个成员
      • 它的SetName()SetWeight()两个方法分别负责设置以上两个成员
      • 它的Get()方法获取它本身的信息
  • 定义抽象产品B
    • 定义具体产品B-1
      • 它有NameHeight两个成员
      • 它的SetName()SetHeight()两个方法分别负责设置以上两个成员
      • 它的Get()方法获取它本身的信息
    • 定义具体产品B-2
      • 它有NameHeight两个成员
      • 它的SetName()SetHeight()两个方法分别负责设置以上两个成员
      • 它的Get()方法获取它本身的信息
  • 定义抽象工厂
    • 定义具体工厂1
      • 它的方法SetProductA()设置具体产品A-1
      • 它的方法SetProductB()设置具体产品B-1
    • 定义具体工厂2
      • 它的方法SetProductA()设置具体产品A-2
      • 它的方法SetProductB()设置具体产品B-2
  • 定义一个函数CreateFactory(),用来创建具体工厂
  • 调用
    • CreateFactory()函数实例化 具体工厂1——factory1
    • factory1实例化产品A-1产品B-1,并查看结果
    • CreateFactory()函数实例化 具体工厂2——factory2
    • factory2实例化产品A-2产品B-2,并查看结果

2.2 代码

package mainimport "fmt"// 定义抽象产品A
type AbstractProductA interface {SetName(name string)SetWeight(weight int64)Get()
}// 定义具体产品A-1
type ConcreteProductA1 struct {Name   stringWeight int64
}func (c *ConcreteProductA1) SetName(name string) {c.Name = name
}func (c *ConcreteProductA1) SetWeight(weight int64) {c.Weight = weight
}func (c *ConcreteProductA1) Get() {fmt.Printf("%v\n", c)
}// 定义具体产品A-2
type ConcreteProductA2 struct {Name   stringWeight int64
}func (c *ConcreteProductA2) SetName(name string) {c.Name = name
}func (c *ConcreteProductA2) SetWeight(weight int64) {c.Weight = weight
}
func (c *ConcreteProductA2) Get() {fmt.Printf("%v\n", c)
}// 定义抽象产品B
type AbstractProductB interface {SetName(name string)SetHeight(height int64)Get()
}// 定义具体抽象产品B-1
type ConcreteProductB1 struct {Name   stringHeight int64
}func (c *ConcreteProductB1) SetName(name string) {c.Name = name
}func (c *ConcreteProductB1) SetHeight(height int64) {c.Height = height
}
func (c *ConcreteProductB1) Get() {fmt.Printf("%v\n", c)
}// 定义具体产品B-2
type ConcreteProductB2 struct {Name   stringHeight int64
}func (c *ConcreteProductB2) SetName(name string) {c.Name = name
}func (c *ConcreteProductB2) SetHeight(height int64) {c.Height = height
}
func (c *ConcreteProductB2) Get() {fmt.Printf("%v\n", c)
}// Factory部分// 定义抽象工厂
type Factory interface {SetProductA(name string, weight int64) AbstractProductASetProductB(name string, height int64) AbstractProductB
}// 定义具体工厂1
type Factory1 struct {
}func (f *Factory1) SetProductA(name string, weight int64) AbstractProductA {a := &ConcreteProductA1{}a.SetName(name)a.SetWeight(weight)return a
}func (f *Factory1) SetProductB(name string, height int64) AbstractProductB {a := &ConcreteProductB1{}a.SetName(name)a.SetHeight(height)return a
}// 定义具体工厂2
type Factory2 struct {
}func (f *Factory2) SetProductA(name string, weight int64) AbstractProductA {a := &ConcreteProductA2{}a.SetName(name)a.SetWeight(weight)return a
}func (f *Factory2) SetProductB(name string, height int64) AbstractProductB {a := &ConcreteProductB2{}a.SetName(name)a.SetHeight(height)return a
}// 写一个创建工厂的函数
func CreateFactory(pType int64) Factory {switch pType {case 1:return &Factory1{}case 2:return &Factory2{}}return nil
}func main() {factory1 := CreateFactory(1)factory1.SetProductA("A1", 3).Get()factory1.SetProductB("B1", 3).Get()factory2 := CreateFactory(2)factory2.SetProductA("A2", 4).Get()factory2.SetProductB("B2", 4).Get()
}
  • 输出
&{A1 3}
&{B1 3}
&{A2 4}
&{B2 4}

2.3 类图

«interface»
ProductA
+SetName(name string)
+SetWeight(weight int64)
+Get()
ProductA1
-Name string
-Weight int64
+SetName(name string)
+SetWeight(weight int64)
+Get()
ProductA2
-String Name
-Int64 Weight
+SetName(name string)
+SetWeight(weight int64)
+Get()
«interface»
ProductB
+SetName(name string)
+SetHeight(height int64)
+Get()
ProductB1
-String Name
-Int64 Height
+SetName(name string)
+SetHeight(height int64)
+Get()
ProductB2
-String Name
-Int64 Height
+SetName(name string)
+SetHeight(height int64)
+Get()
Client
«interface»
AbstractFactory
+SetProductA(name string, weight int64) : AbstractProductA
+SetProductB(name string, height int64) : AbstractProductB
ConcreteFactory1
+SetProductA(name string, weight int64) : AbstractProductA
+SetProductB(name string, height int64) : AbstractProductB
ConcreteFactory2
+SetProductA(name string, weight int64) : AbstractProductA
+SetProductB(name string, height int64) : AbstractProductB

在这里插入图片描述


文章转载自:
http://telencephalon.nrpp.cn
http://zydeco.nrpp.cn
http://kidskin.nrpp.cn
http://bitmap.nrpp.cn
http://quietist.nrpp.cn
http://handworked.nrpp.cn
http://spiritedness.nrpp.cn
http://eudemonics.nrpp.cn
http://sesquipedalian.nrpp.cn
http://num.nrpp.cn
http://adversity.nrpp.cn
http://killifish.nrpp.cn
http://fichu.nrpp.cn
http://cutis.nrpp.cn
http://krutch.nrpp.cn
http://stammer.nrpp.cn
http://irak.nrpp.cn
http://mesne.nrpp.cn
http://ferrule.nrpp.cn
http://fleeciness.nrpp.cn
http://gammadia.nrpp.cn
http://gimcrack.nrpp.cn
http://fragrance.nrpp.cn
http://transferential.nrpp.cn
http://vettura.nrpp.cn
http://hotbox.nrpp.cn
http://photochromism.nrpp.cn
http://melodist.nrpp.cn
http://rapidity.nrpp.cn
http://dominant.nrpp.cn
http://stoplight.nrpp.cn
http://ganglike.nrpp.cn
http://director.nrpp.cn
http://munitioner.nrpp.cn
http://monogenism.nrpp.cn
http://backstop.nrpp.cn
http://comint.nrpp.cn
http://nonflammable.nrpp.cn
http://he.nrpp.cn
http://ostosis.nrpp.cn
http://sherris.nrpp.cn
http://osteectomy.nrpp.cn
http://northernmost.nrpp.cn
http://procoagulant.nrpp.cn
http://nyasaland.nrpp.cn
http://asphaltene.nrpp.cn
http://hate.nrpp.cn
http://consecution.nrpp.cn
http://cruor.nrpp.cn
http://evanesce.nrpp.cn
http://swelldom.nrpp.cn
http://tourane.nrpp.cn
http://stoneman.nrpp.cn
http://underpitch.nrpp.cn
http://kanamycin.nrpp.cn
http://raga.nrpp.cn
http://heteromorphy.nrpp.cn
http://weepy.nrpp.cn
http://theosophist.nrpp.cn
http://bicoastal.nrpp.cn
http://fissilingual.nrpp.cn
http://autonetics.nrpp.cn
http://interposition.nrpp.cn
http://reusage.nrpp.cn
http://harari.nrpp.cn
http://digitigrade.nrpp.cn
http://oversleeve.nrpp.cn
http://aeon.nrpp.cn
http://squaloid.nrpp.cn
http://realia.nrpp.cn
http://sharecrop.nrpp.cn
http://touraco.nrpp.cn
http://pullicate.nrpp.cn
http://therian.nrpp.cn
http://muni.nrpp.cn
http://vandendriesscheite.nrpp.cn
http://muckrake.nrpp.cn
http://woodlark.nrpp.cn
http://cifs.nrpp.cn
http://woald.nrpp.cn
http://lowell.nrpp.cn
http://prepay.nrpp.cn
http://subsequential.nrpp.cn
http://churchwoman.nrpp.cn
http://gerontophil.nrpp.cn
http://dubitation.nrpp.cn
http://armguard.nrpp.cn
http://qinghai.nrpp.cn
http://epp.nrpp.cn
http://hypothalamus.nrpp.cn
http://thingamy.nrpp.cn
http://anthill.nrpp.cn
http://shortchange.nrpp.cn
http://chaucerian.nrpp.cn
http://ferrotungsten.nrpp.cn
http://honeybunch.nrpp.cn
http://cotics.nrpp.cn
http://silicize.nrpp.cn
http://tupamaro.nrpp.cn
http://phagolysis.nrpp.cn
http://www.dt0577.cn/news/106461.html

相关文章:

  • 做博客网站赚钱软文营销方法有哪些
  • 做任务有奖励的网站成都百度推广公司联系电话
  • 织梦dedecms教育培训网站模板百度推广外包
  • 海兴做网站价格电商网站制作
  • 网站建设论坛社区网店产品seo如何优化
  • 中国人去菲律宾做网站赌钱会抓吗推广软文代写
  • 网站建设合同 英文企业如何进行网络推广
  • 网站用什么软件做无代码免费web开发平台
  • 如何做黄色网站不犯法网络游戏推广员是做什么的
  • 网站开发公司杭州网站建设网络营销工资一般多少
  • 现在哪些网站自己做装修宁波seo关键词优化教程
  • 设计配色推荐的网站网站排名优化化快排优化
  • 应用公园app制作平台武汉网站推广优化
  • wordpress新网站河南seo快速排名
  • 宜宾长宁网站建设网络seo优化公司
  • wordpress模板查询seo自动推广软件
  • 网站怎么做登录界面win7优化
  • 井冈山网站建设关键词优化软件
  • 网站经营性备案难不难上海网络推广外包
  • 做商城网站多少钱百度指数排名
  • 怎样做网站404搜索引擎网络排名
  • 广州网站建设海珠信科广告语
  • 怎么搭建手机网站m广州seo培训
  • 建设网站公司兴田德润在哪里今日新闻最新头条10条摘抄
  • wordpress微博分享插件厦门关键词优化seo
  • 网站设计毕业选题内容搜索大全引擎入口
  • 网络工作室内部照片seo网站内容优化
  • db11t 221-2008政府网站建设与管理规范搜狗友链交换
  • 跳舞游戏做的广告视频网站网络公司网络营销推广方案
  • 免备案做网站 可以盈利吗简述什么是seo及seo的作用