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

基于h5的wap网站开发seo专员是做什么的

基于h5的wap网站开发,seo专员是做什么的,姓氏头像在线制作免费生成图片,网站建设客源以下是基于Python实现的23种设计模式及代码段和详细解释: 1. 工厂模式(Factory Pattern) 简介 工厂模式是一种创建型设计模式,它允许客户端代码通过工厂方法创建对象,而无需直接实例化对象。在工厂方法模式中&#…

以下是基于Python实现的23种设计模式及代码段和详细解释:

1. 工厂模式(Factory Pattern)

简介

工厂模式是一种创建型设计模式,它允许客户端代码通过工厂方法创建对象,而无需直接实例化对象。在工厂方法模式中,我们定义一个工厂方法来创建对象,而不是使用类的构造函数。

代码段

from abc import ABC, abstractmethodclass Product(ABC):"""抽象产品类,定义所有具体产品的接口"""@abstractmethoddef operation(self) -> str:passclass ConcreteProduct(Product):"""具体产品类"""def operation(self) -> str:return "ConcreteProduct"class Creator(ABC):"""抽象创建者类,声明工厂方法,返回一个产品类的实例"""@abstractmethoddef factory_method(self) -> Product:passdef some_operation(self) -> str:"""可选:创建者还可以提供一些默认实现"""product = self.factory_method()result = f"Creator: {product.operation()}"return resultclass ConcreteCreator1(Creator):"""具体创建者1,实现工厂方法以返回具体产品1的实例"""def factory_method(self) -> Product:return ConcreteProduct()class ConcreteCreator2(Creator):"""具体创建者2,实现工厂方法以返回具体产品2的实例"""def factory_method(self) -> Product:return ConcreteProduct()def client_code(creator: Creator) -> None:"""客户端代码只需要知道创建者的抽象类,无需关心具体实现类"""print(f"Client: I'm not aware of the creator's class, but it still works.\n"f"{creator.some_operation()}", end="")if __name__ == "__main__":print("App: Launched with the ConcreteCreator1.")client_code(ConcreteCreator1())

解释

该代码段演示了工厂模式,其中有一个抽象产品类和其具体实现类。还有一个抽象创建者类来声明工厂方法和可选的默认实现。具体创建类实现工厂方法以返回具体产品类的实例。客户端代码调用抽象创建者而不是具体创建子类。

2. 抽象工厂模式(Abstract Factory Pattern)

简介

抽象工厂是一种创建型设计模式,它允许您创建一组相关的对象,而无需指定其具体类。抽象工厂定义了一个接口,用于创建相关的对象,而不指定具体类。

代码段

from abc import ABC, abstractmethodclass AbstractFactory(ABC):"""抽象工厂类,声明所有产品创建方法。"""@abstractmethoddef create_product_a(self):pass@abstractmethoddef create_product_b(self):passclass ConcreteFactory1(AbstractFactory):"""具体工厂1,生成一组具有相互依赖关系的产品。"""def create_product_a(self):return ConcreteProductA1()def create_product_b(self):return ConcreteProductB1()class ConcreteFactory2(AbstractFactory):"""具体工厂2,生成一组具有相互依赖关系的产品。"""def create_product_a(self):return ConcreteProductA2()def create_product_b(self):return ConcreteProductB2()class AbstractProductA(ABC):"""抽象产品A类,定义具体产品共有的方法"""@abstractmethoddef useful_function_a(self) -> str:passclass AbstractProductB(ABC):"""抽象产品B类,定义具体产品共有的方法"""@abstractmethoddef useful_function_b(self) -> None:pass@abstractmethoddef another_useful_function_b(self, collaborator: AbstractProductA) -> None:passclass ConcreteProductA1(AbstractProductA):"""具体产品A1,实现抽象产品A类的接口"""def useful_function_a(self) -> str:return "The result of the product A1."class ConcreteProductA2(AbstractProductA):"""具体产品A2,实现抽象产品A类的接口"""def useful_function_a(self) -> str:return "The result of the product A2."class ConcreteProductB1(AbstractProductB):"""具体产品B1,实现抽象产品B类的接口"""def useful_function_b(self) -> str:return "The result of the product B1."def another_useful_function_b(self, collaborator: AbstractProductA) -> str:"""B1实现了与特定产品A相关的功能。"""result = collaborator.useful_function_a()return f"The result of the B1 collaborating with the ({result})"class ConcreteProductB2(AbstractProductB):"""具体产品B2,实现抽象产品B类的接口"""def useful_function_b(self) -> str:return "The result of the product B2."def another_useful_function_b(self, collaborator: AbstractProductA) -> str:"""B2实现了与特定产品A相关的功能。"""result = collaborator.useful_function_a()return f"The result of the B2 collaborating with the ({result})"def client_code(factory: AbstractFactory) -> None:"""客户端代码仅与抽象工厂及其产品接口一起使用。"""product_a = factory.create_product_a()product_b = factory.create_product_b()print(f"{product_b.useful_function_b()}")print(f"{product_b.another_useful_function_b(product_a)}", end="")if __name__ == "__main__":print("Client: Testing client code with the first factory type...")client_code(ConcreteFactory1())print("\n")print("Client: Testing the same client code with the second factory type...")client_code(ConcreteFactory2())

解释

该代码段演示了抽象工厂模式,其中有一个抽象工厂类和多个实现不同产品分类的具体工厂类。每个工厂类都实现了工厂方法来生产不同类型的产品。每个产品类实现了共同的抽象产品接口。客户端代码只与抽象工厂和产品接口一起使用,而不需要关心具体实现类。

3. 建造者模式(Builder Pattern)

简介

建造者模式是一种创建型设计模式,它允许您使用相同的构建代码生成不同类型和形式的对象。建造者模式的精髓在于将对象构建过程与其表示分离。

代码段

from abc import ABC, abstractmethod
from typing import Anyclass Builder(ABC):"""抽象建造者类,声明所有产品构建步骤。"""@abstractmethoddef produce_part_a(self) -> None:pass@abstractmethoddef produce_part_b(self) -> None:pass@abstractmethoddef produce_part_c(self) -> None:pass@abstractmethoddef get_result(self) -> Any:passclass ConcreteBuilder1(Builder):"""具体建造者类1,实现所有产品构建方法,并返回最终结果。"""def __init__(self) -> None:self.reset()def reset(self) -> None:self.product = Product1()def produce_part_a(self) -> None:self.product.add("PartA1")def produce_part_b(self) -> None:self.product.add("PartB1")def produce_part_c(self) -> None:self.product.add("PartC1")def get_result(self) -> Product1:result = self.productself.reset()return resultclass ConcreteBuilder2(Builder):"""具体建造者类2,实现所有产品构建方法,并返回最终结果。"""def __init__(self) -> None:self.reset()def reset(self) -> None:self.product = Product2()def produce_part_a(self) -> None:self.product.add("PartA2")

http://www.dt0577.cn/news/27444.html

相关文章:

  • 河南住房和城乡建设厅网站资质推广模式包括哪些模式
  • 网站开发的职业决策国家免费技能培训
  • 承德网站制作网站seo诊断技巧
  • 商城网站建设需要注意什么天津seo网站管理
  • 怎么建设一个自己的电商网站成都seo公司
  • 樟木头网站建设中国十大seo公司
  • 怎么修改网站标题关键词描述销售培训课程
  • 室内装修设计软件电脑版seo学院培训班
  • 信号增强器设置网站西昌seo快速排名
  • 深圳动态科技集团网站代运营一家店铺多少钱
  • 为什么要做网站首页设计经典模板网站建设
  • APP网站建设什么用处ip网站查询服务器
  • 郑州网站建设氵汉狮网络泰州网站整站优化
  • 福建百度推广西安seo优化顾问
  • 天津做网站公司哪家好网络推广平台哪家公司最好
  • 锡盟网站建设网站搜索优化技巧
  • 免费个人网站域名百度云资源搜索引擎入口
  • php语言 网站建设seo是指什么职位
  • 婚礼策划网站模板行者seo无敌
  • 网站开发注册个体工商百度今日数据
  • 建网站和做微信哪个好百度搜索工具
  • 烟台cms建站模板成人职业培训机构
  • ai写作网站竞价推广账户竞价托管公司
  • 高逼格网站百度学术官网论文查重免费
  • 什么网站上做奥数题网站测试的内容有哪些
  • 新疆建设网络培训学院网络优化工程师简历
  • wordpress 主机要求淘宝seo排名优化软件
  • 公司自己的网站怎样做willfast优化工具下载
  • 登录贵州省住房和城乡建设厅网站2345网址导航官网下载安装
  • 邹带芽在成武建设局网站在百度上怎么发布信息