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

网站建设服务合同书标准版cms做网站后台

网站建设服务合同书标准版,cms做网站后台,做商城网站的企业,商品推广软文800字简介 设计模式是为了解决一些出现的问题设计的解决方案。是长时间经验的总结#xff0c;是根据不同问题从而提出并且实践出来的解决办法。使用不同的设计模式可以解决不同的问题。 设计模式可以分为三种大类别#xff1a;分别是创建型模式、结构型模式、行为型模式。 在开发…简介 设计模式是为了解决一些出现的问题设计的解决方案。是长时间经验的总结是根据不同问题从而提出并且实践出来的解决办法。使用不同的设计模式可以解决不同的问题。 设计模式可以分为三种大类别分别是创建型模式、结构型模式、行为型模式。 在开发中假设不使用设计模式可能会造成耦合度过高会造成一定的代码冗余而且可能会影响后续的开发进程合理的使用适合的设计模式会提高整体的灵活性降低后续的维护成本。 创建型模式顾名思义是处理对象创建的设计模式降低复杂度创建复杂对象时使用。 工厂模式 在类中实现一个接口创建指定对象使一个类的实例化延迟到了子类。简单来说把类的创建都封装起来只需要调用一个子类方法就可以实现类的创建并不会暴露创建类的逻辑。 以下为一个工厂类的实例 python代码如下 #原创不易多多支持 #Bloghttps://me.csdn.net/A757291228 class Factory:def getFruit(self, name, color, taste ):if name apple:return Apple(color,taste)class Fruit:def __init__(self):print(水果类初始化)def get_color(self):return self.colordef get_taste(self):return self.tasteclass Apple(Fruit):def __init__(self,color,taste):print(苹果初始化)self.color colorself.taste tasteclass Banana(Fruit):def __init__(self,color,taste):print(香蕉初始化)self.color colorself.taste tasteif __name__ __main__:factory Factory()appleClass factory.getFruit(apple, green, sweet)print(苹果的颜色,appleClass.get_color(),苹果的味道,appleClass.get_taste())C代码如下 //原创不易多多支持 //Bloghttps://me.csdn.net/A757291228#include iostream using namespace std;class Fruit {public:string color;string taste;Fruit() {} };class Apple : public Fruit {public:Apple(string color, string taste) {this-color color;this-taste taste;cout 苹果类创建 endl;} };class Factory {public:Fruit* getFruit(string name, string color, string taste){if (name apple) {return new Apple(color, taste);}} };int main(){Factory* factory new Factory();Fruit* applefactory-getFruit(apple, 红,甜的);cout 苹果的味道 apple -color endl; }从以上代码实例可以看出每次新建类只需要知道类的特定标号或者说特定的名称即可不需要关心类的实现逻辑在一定程度上减少了代码冗余减少了重复做功但是也暴露了一个问题每次要新增一个类都需要在工厂类中去实现逻辑也增强了之间的耦合度所有的类的创建都给了一个工厂去进行当你的类的种类繁多时你的代码会显得臃肿不堪所以设计模式需要考量当前项目需求是否符合此模式再进行使用。 抽象工厂模式 单独的一个工厂去创建所有类型的类会显得这个工厂臃肿不堪那么创建多个工厂不就ok了每个工厂都做一种类别的事情。就像上班一样有前端后端、UI、运维一样每个人都分工合作这样就很有调理了。 抽象工厂很好的解决了这个问题。以下为抽象工厂示例代码。 以下代码从以上的示例代码基础上增加了绘制 根据上面代码进行修改我们定义几个食物基类Food定义其它几个类别例如水果、主食以及蔬菜这是几种不同类别的食物。再定3个工厂分别用来处理不同的食物这样就不用担心所有的类都放一个工厂进行处理了最后再定义一个抽象工厂类这个类对所有的工厂进行一个统一封装这样就实现了抽象工厂类。 python代码 #抽象工厂主工厂 #原创不易多多支持 #Bloghttps://me.csdn.net/A757291228 class MainFactory:def getFactory(self,factory_name):if factory_nameFruit:return FruitFactory()elif factory_nameVegetables:return VegetablesFactory()elif factory_nameStaple:return StapleFactory() #工厂类 class FruitFactory:def getFruit(self, name, color, taste ):if name apple:return Apple(color,taste) class VegetablesFactory:def getFruit(self, name, color, taste ):if name carrot:return Carrot(color,taste) class StapleFactory:def getFruit(self, name, color, taste ):if name rice:return Rice(color,taste)#Food 基类 class Food:def __init__(self,taste):print(食物类初始化)self.taste taste #水果主食和蔬菜三个基类 class Fruit(Food):def __init__(self):print(水果类初始化)def get_color(self):return self.colordef get_taste(self):return self.tasteclass Vegetables(Food):def __init__(self):print(蔬菜类初始化)def get_color(self):return self.colordef get_taste(self):return self.tasteclass Staple(Food):def __init__(self):print(主食类初始化)def get_color(self):return self.colordef get_taste(self): return self.taste #具体类别 class Apple(Fruit):def __init__(self,color,taste):print(苹果初始化)self.color colorself.taste taste class Rice(Staple):def __init__(self,color,taste):print(米饭初始化)self.color colorself.taste tasteclass Carrot(Vegetables):def __init__(self,color,taste):print(红萝卜初始化)self.color colorself.taste tasteif __name__ __main__:mainFactory MainFactory()fruitFactorymainFactory.getFactory(Fruit)applefruitFactory.getFruit(apple, green, sweet)print(苹果的颜色,apple.color,苹果的口味,apple.taste) C实现 #include iostream using namespace std; //原创不易多多支持 //Bloghttps://me.csdn.net/A757291228//食物基类 class Food { public:string color;string taste;Food() {} };//三个类别 class Fruit :public Food { public:Fruit() {} };class Vegetables :public Food { public:Vegetables() {} };class Staple :public Food { public:Staple() {} }; //三个具体类 class Apple : public Fruit { public:Apple(string color, string taste) {this-color color;this-taste taste;cout 苹果类创建 endl;} };class Rice : public Staple { public:Rice(string color, string taste) {this-color color;this-taste taste;cout 苹果类创建 endl;} };class Carrot : public Vegetables { public:Carrot(string color, string taste) {this-color color;this-taste taste;cout 苹果类创建 endl;} };//工厂基类 class Factory { public:virtual Food* getFood(){} }; //具体工厂类 class FruitFactory { public:Food* getFood(string name, string color, string taste){if (name apple) {return new Apple(color, taste);}} }; class StapleFactory { public:Food* getFood(string name, string color, string taste){if (name apple) {return new Apple(color, taste);}} }; class VegetablesFactory { public:Fruit* getFood(string name, string color, string taste){if (name apple) {return new Apple(color, taste);}} }; //主工厂抽象工厂 class MainFactory { public:FruitFactory* getFactory(string factory_name){if (factory_name Fruit) {return new FruitFactory();}} };int main() {MainFactory* main_factory new MainFactory();FruitFactory* fruit main_factory-getFactory(Fruit);Food* apple fruit-getFood(apple, 红, 甜甜的);cout 苹果的味道 apple-taste endl; }以上代码都通过了抽象工厂进行统一的不同属性的工厂调用增强了逻辑和结构。 看到这里了点个赞呗~(本来说要加C#和Java的觉得麻烦就没写了后面有时间就补)
http://www.pierceye.com/news/721261/

相关文章:

  • 凡网站建设网站线下推广怎么做
  • 简要描述创建商务站点的商务镇江海绵城市建设官方网站
  • 广东建设局网站首页物流官网网站
  • 网站首页做多大分辨率卖域名做非法网站
  • 内蒙古自治区建设厅网站首页网站如何做cdn
  • 代做计算机毕业设计网站福田庆三明星案例
  • 常用seo站长工具微商引流推广平台
  • 潍坊市作风建设年官方网站央视新闻
  • 东阳app开发广东seo网站设计价格
  • 医院网站开发门诊部网站建设
  • 卫生系统网站的建设和维护uc浏览器官网
  • 曲靖网站制作一条龙深圳网站建设的特殊性
  • 网站建设技术课程设计儿童教育网站怎么做有趣
  • 建设银行网站网址网站推广在线
  • 服务器上网站建设用什么搭建个人网站
  • 网站设计排版怎么做wordpress添加媒体
  • 网站服务器镜像外协加工网最新订单
  • 做网站要准备的资料广州响应式网站
  • 徐州网站建设方案维护wordpress主页访客记录
  • 西安网站优化招聘网多个网站 备案吗
  • 宣威网站wordpress 园林模板
  • 宁夏政务大厅城乡建设厅口网站怎么用抓爬工具做网站
  • 电影网站怎么建设深圳企业营销型网站
  • 天津工程建设网官方网站wordpress 静态化插件
  • 洛阳公司青峰做的企业网站设计本app
  • 宁波网站建设设计高效的设计公司
  • c2c网站架构免费推广网站工具
  • 网站建设案例基本流程图咨询公司名字大全
  • 成功的电子商务网站设计律师推广网站排名
  • 东莞桥头网站建设合肥商城网站建设