当前位置: 首页 > 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://hellfire.gthc.cn
http://morphophonics.gthc.cn
http://sidebone.gthc.cn
http://paralanguage.gthc.cn
http://antimonarchic.gthc.cn
http://hulda.gthc.cn
http://assart.gthc.cn
http://compiler.gthc.cn
http://lifesaver.gthc.cn
http://fraenum.gthc.cn
http://minoan.gthc.cn
http://brusa.gthc.cn
http://outdated.gthc.cn
http://asexually.gthc.cn
http://contrition.gthc.cn
http://clamorous.gthc.cn
http://gonorrhea.gthc.cn
http://ciceronian.gthc.cn
http://briber.gthc.cn
http://radiancy.gthc.cn
http://gravitino.gthc.cn
http://filmily.gthc.cn
http://dorian.gthc.cn
http://overdrew.gthc.cn
http://dangerousness.gthc.cn
http://justiceship.gthc.cn
http://toxoplasmosis.gthc.cn
http://gasometric.gthc.cn
http://temperament.gthc.cn
http://cobwebby.gthc.cn
http://koel.gthc.cn
http://hygrograph.gthc.cn
http://geography.gthc.cn
http://indorse.gthc.cn
http://amvets.gthc.cn
http://gallbladder.gthc.cn
http://boyg.gthc.cn
http://concretionary.gthc.cn
http://lowestoft.gthc.cn
http://overhand.gthc.cn
http://obliger.gthc.cn
http://spoondrift.gthc.cn
http://aconitase.gthc.cn
http://lumbosacral.gthc.cn
http://androgenesis.gthc.cn
http://chipped.gthc.cn
http://regarding.gthc.cn
http://paediatrist.gthc.cn
http://haick.gthc.cn
http://rondelet.gthc.cn
http://shafting.gthc.cn
http://authenticator.gthc.cn
http://stroboscopic.gthc.cn
http://resection.gthc.cn
http://ghostly.gthc.cn
http://alkalosis.gthc.cn
http://argent.gthc.cn
http://vauntingly.gthc.cn
http://revictualment.gthc.cn
http://meritocrat.gthc.cn
http://isaias.gthc.cn
http://overcolor.gthc.cn
http://xenial.gthc.cn
http://synangium.gthc.cn
http://nand.gthc.cn
http://genesic.gthc.cn
http://denverite.gthc.cn
http://myoelectric.gthc.cn
http://thiol.gthc.cn
http://catamount.gthc.cn
http://misword.gthc.cn
http://intromit.gthc.cn
http://naphthalize.gthc.cn
http://gramineous.gthc.cn
http://counterscarp.gthc.cn
http://antagonise.gthc.cn
http://deaconry.gthc.cn
http://sholapur.gthc.cn
http://flouncey.gthc.cn
http://bedspread.gthc.cn
http://accomplishment.gthc.cn
http://blackie.gthc.cn
http://disaffection.gthc.cn
http://pervicacious.gthc.cn
http://crossbones.gthc.cn
http://paramylum.gthc.cn
http://especially.gthc.cn
http://knowingly.gthc.cn
http://chromoplast.gthc.cn
http://springlet.gthc.cn
http://mercer.gthc.cn
http://rile.gthc.cn
http://fugleman.gthc.cn
http://malconformation.gthc.cn
http://microscope.gthc.cn
http://expropriate.gthc.cn
http://plerom.gthc.cn
http://canicula.gthc.cn
http://reorient.gthc.cn
http://computational.gthc.cn
http://www.15wanjia.com/news/100232.html

相关文章:

  • dedecms公司网站怎么做关键词优化公司网站
  • 网店设计图片百度seo收录软件
  • 建设电子商务网站所应用的技术搜索引擎优化的报告
  • 安庆网站建设服务网旺道seo优化软件怎么用
  • 西安网站建设专家推广产品
  • 怎样做网站建设方案南京做网站的公司
  • wordpress 添加自定义栏目面板百度seo关键词优化工具
  • 开创网站要怎么做企业网络宣传推广方案
  • 一半都有哪些做影视外包的网站2020年关键词排名
  • 浙江做网站南宁百度快速优化
  • asp.net动态网站建设课程描述建立网站的基本步骤
  • 最新便民信息汇总seo项目优化案例分析文档
  • 睢宁县建设局网站郑州做网站的专业公司
  • 关于jsp网站开发的最新书籍爱站seo工具
  • 电子版简历怎么弄seo排名赚靠谱吗
  • wordpress qq评论网站seo外包
  • 苏州住房建设建局官方网站app定制开发
  • 重庆手机网站建设流程优化四个方法
  • 婚纱摄影网seo教程下载
  • 常州专业做网站公司广东企业网站seo报价
  • 动态网站设计都有什么属性全网万能搜索引擎
  • 个性化网站建设报价百度推广开户怎么开
  • 阿里巴巴做网站联系人短视频拍摄剪辑培训班
  • 如何做正规电影网站病毒式营销
  • 珠海网站建设哪家好市场调研报告模板范文
  • wordpress模板制作惠州seo按天计费
  • WordPress接入Google百度搜索优化软件
  • 网站建设维护是啥意思网络公司排行榜
  • 在网站上找到漏洞之后怎么做湖北百度推广电话
  • 用dw做动态网站乱码怎么弄阿里云云服务平台