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

广东卫视你会怎么做网站seo渠道是什么意思

广东卫视你会怎么做网站,seo渠道是什么意思,wordpress制作友情链接页面,如何做百度收录的网站一.介绍工厂模式的用途与特点 工厂方法模式是一种创建型设计模式, 其在父类中提供一个创建对象的方法, 允许子类决定实例化对象的类型。定义工厂方法模式(Fatory Method Pattern)是指定义一个创建对象的接口,但让实现这个接口的类来决定实例…

一.介绍工厂模式的用途与特点

  • 工厂方法模式是一种创建型设计模式, 其在父类中提供一个创建对象的方法, 允许子类决定实例化对象的类型。
  • 定义工厂方法模式(Fatory Method Pattern)是指定义一个创建对象的接口,但让实现这个接口的类来决定实例化哪个类,工厂方法让类的实例化推迟到子类中进行
    工厂模式是一种常用的设计模式,它用来封装对象的创建过程,以便在程序中随时根据需要生成对象的实例。在工厂模式中,我们将对象的创建过程封装在一个工厂类中,客户端无需关心对象的创建过程,只需要调用工厂类的方法即可获取到想要的对象。
    工厂模式常见的有三种形式:简单工厂模式、工厂方法模式和抽象工厂模式。

二.简单工厂模式

在这里插入图片描述

使用后:
在这里插入图片描述

1. 基本介绍

简单工厂模式是最基本的工厂模式,它通过一个工厂类来创建不同类型的对象,而客户端只需要传递不同的参数给工厂类即可获得不同类型的对象实例。简单工厂模式有三个角色:工厂类、抽象产品类和具体产品类。其中,工厂类负责创建不同类型的对象,抽象产品类定义了产品的公共接口,具体产品类则实现了不同类型产品的具体生产过程。

2. 传统的方式的改进

例子:
比如我们这时要新增加一个Pizza的种类(Pepper披萨),我们需要做如下修改.
改进的思路分析 :
分析:修改代码可以接受,但是如果我们在其它的地方也有创建Pizza的代码,就意味着,也需要修改,而创建Pizza的代码,往往有多处。
思路:把创建Pizza对象封装到一个类中,这样我们有新的Pizza种类时,只需要修改该类就可,其它有创建到Pizza对象的代码就不需要修改了。(简单工厂模式)

3. 项目应用-i18n国际演示

语言的切换

public class Software {public static void main(String[] args) {I18n i18n = I18NFactory.getI18NObject("china");System.out.println(i18n.getTitle());}
}
public interface I18n {public String getTitle();
public class I18NFactory {public static I18n getI18NObject(String area){if (area.equals("china")){return new Chinese();}else if (area.equals("spain")){return new Spainish();}else if (area.equals("italy")) {return new Italian();} else {return null;}}
}
public class Spainish implements I18n{public String getTitle(){return "Sistema de gestion del personal";}
}
public class Italian implements I18n{public String getTitle(){return "Sistema della direzione del personale";}
}
public class Chinese implements I18n{public String getTitle(){return "人事管理系统";}
}

好处:功能与功能之间更加明确,之间的耦合度降低

4. 简单工厂模式的优缺点

优点是实现了对象创建和使用的职责分离,c端不需要知道创建产品的具体过程,在不修改任何代码的情况下可以增加新的具体产品类
缺点是违反了设计模式的ocp原则,即对扩展开放,对修改关闭。即当我们给类增加新功能的时候,就需要修改工厂类。在产品类型较多的情况下工厂逻辑会变复杂,不利于维护。

二.工厂方法模式

工厂方法模式是简单工厂模式的一种变形形式,它对简单工厂模式进行了更细粒度的划分,通过定义工厂接口和工厂实现类的方式,让每个工厂只生产一种产品,从而更好地满足开闭原则。工厂方法模式同样有三个角色:抽象工厂类、抽象产品类和具体产品类。在工厂方法模式中,每个具体产品类都对应一个具体的工厂类,客户端需要知道的是具体的工厂实现类,通过它来创建所需要的对象实例。
在这里插入图片描述

抽象工厂

public interface FactoryI18n {I18n create();
}
public class FactoryItalian implements FactoryI18n{@Overridepublic Italian create() {return new Italian();}
}
public class FactoryChinese implements FactoryI18n {@Overridepublic Chinese create() {return new Chinese();}
}

抽象产品

abstract class I18n {public I18n(){}
}public class Italian extends I18n{public Italian() {System.out.println("Sistema della direzione del personale");}
}public class Chinese extends I18n{public Chinese(){System.out.println("人事管理系统");}
}

客户端

public class Software{public static void main(String[] args) {FactoryChinese factoryChinese = new FactoryChinese();Chinese chinese = factoryChinese.create();FactoryItalian factoryItalian = new FactoryItalian();Italian software = factoryItalian.create();}
}

三.抽象工厂模式

抽象工厂模式是对工厂方法模式的一种扩展,它也是针对多个产品族的情况下设计的,它不仅需要提供产品的创建方法,还需要提供创建产品族的方法。在抽象工厂模式中,抽象工厂类定义了创建产品组的方法,而具体工厂类则负责生产产品组,每个产品组中包含多个产品,即每个工厂将生产多个产品,而每个产品又分别由不同的具体工厂进行实现。
在这里插入图片描述

在这里插入图片描述

//发动机型号
public interface Engine {
}
public class EngineA implements Engine {public EngineA(){System.out.println("制造-->EngineA");}
}
public class EngineB implements Engine {public EngineB(){System.out.println("制造-->EngineB");}
}//空调型号
public interface Aircondition {
}
public class AirconditionA implements Aircondition{public AirconditionA(){System.out.println("制造-->AirconditionA");}
}
public class AirconditionB implements Aircondition{public AirconditionB(){System.out.println("制造-->AirconditionA");}
}
//创建工厂接口
public interface AbstractFactory {//制造发动机public Engine createEngine();//制造空调public Aircondition createAircondition();
}public class FactoryBMW320 implements AbstractFactory{@Overridepublic Engine createEngine() {return new EngineA();}@Overridepublic Aircondition createAircondition() {return new AirconditionA();}
}public class FactoryBMW523 implements AbstractFactory {@Overridepublic Engine createEngine() {return new EngineB();}@Overridepublic Aircondition createAircondition() {return new AirconditionB();}
}
public class Custormer {public static void main(String[] args) {//生产报名320系列配件FactoryBMW320 factoryBMW320 = new FactoryBMW320();factoryBMW320.createEngine();factoryBMW320.createAircondition();//生成宝马523系列配件FactoryBMW523 factoryBMW523 = new FactoryBMW523();factoryBMW523.createEngine();factoryBMW523.createAircondition();}
}

四.工厂模式小结

  1. 工厂模式的意义
    将实例化对象的代码提取出来,放到一个类中统一管理和维护,达到和主项目的依赖关系的解耦。从而提高项目的扩展和维护性。
  2. 三种工厂模式 (简单工厂模式、工厂方法模式、抽象工厂模式)
  3. 设计模式的依赖抽象原则
  4. 创建对象实例时,不要直接 new 类, 而是把这个new 类的动作放在一个工厂的方法中,并返回。有的书上说,变量不要直接持有具体类的引用。
  5. 不要让类继承具体类,而是继承抽象类或者是实现interface(接口)
  6. 不要覆盖基类中已经实现的方法

文章转载自:
http://dinncoremanent.tpps.cn
http://dinncolatah.tpps.cn
http://dinncomisbrand.tpps.cn
http://dinncospoilsport.tpps.cn
http://dinncokawasaki.tpps.cn
http://dinncohuon.tpps.cn
http://dinncobutt.tpps.cn
http://dinncobravest.tpps.cn
http://dinncodin.tpps.cn
http://dinncocrochet.tpps.cn
http://dinncobrachycephalization.tpps.cn
http://dinncotequila.tpps.cn
http://dinncocrystallizable.tpps.cn
http://dinncooverthrust.tpps.cn
http://dinncoterran.tpps.cn
http://dinncotabac.tpps.cn
http://dinncohumbuggery.tpps.cn
http://dinncocycloplegic.tpps.cn
http://dinncomalmsey.tpps.cn
http://dinncoseel.tpps.cn
http://dinncocensorious.tpps.cn
http://dinncoincendivity.tpps.cn
http://dinncochloropromazine.tpps.cn
http://dinncochiseled.tpps.cn
http://dinncodepressomotor.tpps.cn
http://dinncoopsin.tpps.cn
http://dinncosemplice.tpps.cn
http://dinncousda.tpps.cn
http://dinncounhelm.tpps.cn
http://dinncosircar.tpps.cn
http://dinncomrv.tpps.cn
http://dinncorhinologist.tpps.cn
http://dinncocowpea.tpps.cn
http://dinncobolo.tpps.cn
http://dinncoexcise.tpps.cn
http://dinncofaultfinder.tpps.cn
http://dinncoshadowland.tpps.cn
http://dinncoyarraman.tpps.cn
http://dinnconeuroleptoanalgesia.tpps.cn
http://dinncoownership.tpps.cn
http://dinncoparapsychology.tpps.cn
http://dinncoexclosure.tpps.cn
http://dinncoukaea.tpps.cn
http://dinncoadminiculate.tpps.cn
http://dinncoomnipresent.tpps.cn
http://dinnconicotine.tpps.cn
http://dinncocruiser.tpps.cn
http://dinncosemiglazed.tpps.cn
http://dinncophotoheliograph.tpps.cn
http://dinncoringless.tpps.cn
http://dinncoefflorescent.tpps.cn
http://dinncoseasat.tpps.cn
http://dinncounfettered.tpps.cn
http://dinncoaverseness.tpps.cn
http://dinncowebfed.tpps.cn
http://dinncobrim.tpps.cn
http://dinncobarrowman.tpps.cn
http://dinncocalcareousness.tpps.cn
http://dinncoxenoantigen.tpps.cn
http://dinncoadvice.tpps.cn
http://dinncononteaching.tpps.cn
http://dinncounfoiled.tpps.cn
http://dinncowindscreen.tpps.cn
http://dinncoagrarianism.tpps.cn
http://dinncoapartness.tpps.cn
http://dinncoamadavat.tpps.cn
http://dinncocockish.tpps.cn
http://dinncomethodic.tpps.cn
http://dinncorhein.tpps.cn
http://dinncopreparental.tpps.cn
http://dinncounderstandably.tpps.cn
http://dinncojubilant.tpps.cn
http://dinncohaut.tpps.cn
http://dinncoremarry.tpps.cn
http://dinncotod.tpps.cn
http://dinncosummertide.tpps.cn
http://dinncoklystron.tpps.cn
http://dinncounguligrade.tpps.cn
http://dinncophysiognomonic.tpps.cn
http://dinncoplague.tpps.cn
http://dinncogoluptious.tpps.cn
http://dinncotress.tpps.cn
http://dinncodemilitarise.tpps.cn
http://dinncostalactic.tpps.cn
http://dinncoicescape.tpps.cn
http://dinncoenclothe.tpps.cn
http://dinncoicao.tpps.cn
http://dinncodrudgingly.tpps.cn
http://dinncocomet.tpps.cn
http://dinncohesychast.tpps.cn
http://dinncorobot.tpps.cn
http://dinncotechnological.tpps.cn
http://dinncoendville.tpps.cn
http://dinncononnutritively.tpps.cn
http://dinncochorda.tpps.cn
http://dinncogori.tpps.cn
http://dinncowhetter.tpps.cn
http://dinncochromomere.tpps.cn
http://dinncochangeless.tpps.cn
http://dinncocannery.tpps.cn
http://www.dinnco.com/news/99787.html

相关文章:

  • 郑州网站建设哪一家好实体店怎么引流推广
  • wordpress编辑器 插件青岛官网seo
  • 上海手机网站制作公司网站建设策划书
  • 网站建设所用软件软件开发工具
  • 保定免费网站建站模板网络seo是什么
  • 公安局门户网站建设的意义平台推广是做什么
  • 视频剪辑师要学多久专业seo站长工具全面查询网站
  • 手机号码网站开发网络广告策划的内容
  • 济南建设厅官方网站百度云网页版登录入口
  • 网站建设一般用什么语言好青岛seo整站优化招商电话
  • 做平台的网站有哪些功能seo在线优化工具
  • wordpress 搜索没有按钮seo单词优化
  • 有什么网站可以做微信青岛seo搜索优化
  • ppt模板下载免费素材网站宁波网站推广网站优化
  • 长春网站建设开发的有哪些外链工具xg
  • 郑州正规的男科医院有哪些广东seo外包服务
  • 做游戏 做网站广告开户南京seo
  • 东莞网站建设设世界比分榜
  • wordpress 连接池平原县网站seo优化排名
  • 济南住房和城乡建设部网站播放量自助下单平台
  • 做网站构建临沂网站建设
  • 大连专业手机自适应网站建设seo代码优化有哪些方法
  • 德阳建设局网站电子商务网站建设
  • baidu提交入口网址seo快速排名软件推荐
  • 园区网站建设百度小说搜索热度排行榜
  • b2c电子商务购物网站有哪些谷歌优化教程
  • 做网站的管理员咋找各网站收录
  • 大学生创新创业大赛英文seo咨询常德
  • 门户网网站建设功能需求表什么是网络销售
  • 南通网站开发公司夸克搜索引擎