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

企业建网站多少钱较成功营销网站的例子

企业建网站多少钱,较成功营销网站的例子,网上销售平台,做网站设计师要提供什么设计模式 文章目录 设计模式工厂模式创建方法#xff08;Create Methods#xff09;简单工厂#xff08;Simple Factory#xff09;工厂方法#xff08;Method Factory#xff09;抽象工厂#xff08;Abstract Factroy#xff09; 策略模式 工厂模式 创建方法#xf…设计模式 文章目录 设计模式工厂模式创建方法Create Methods简单工厂Simple Factory工厂方法Method Factory抽象工厂Abstract Factroy 策略模式 工厂模式 创建方法Create Methods 调用构造函数进行封装隐藏创建细节体现代码意图增强代码可维护性 例如我们有一个部门部门中有一个工种程序员 public class Programmer { } // 程序员类 public class Department // 部门类 {// 这是一个创建方法(也可以写成静态)public Programmer CreateEmployee(){return new Programmer();} }调用创建方法 Department department new Department(); Programmer programmer department.CreateEmployee();简单工厂Simple Factory 现在部门增加了一个工种设计师工种那么我们使用简单工厂模式通过给定参数的不同来创建不同的对象 // 工种枚举 public enum EEmployeeType {Programmer,Designer } public class Employee {} // 工种父类 public class Programmer : Employee { } // 程序员类 public class Designer : Employee { } // 设计师类 public class Department // 部门类 {// 用简单工厂实现创建方法public Employee CreateEmployee(EEmployeeType employeeType){Employee employee new Employee();switch (employeeType){case EEmployeeType.Programmer:employee new Programmer();break;case EEmployeeType.Designer:employee new Designer();break;default:throw new System.ArgumentException(Invalid employee type);}return employee;} }调用创建方法 Department department new Department(); Employee programmer department.CreateEmployee(EEmployeeType.Programmer); Employee designer department.CreateEmployee(EEmployeeType.Designer);工厂方法Method Factory 创建子类工厂 如果现在又又需要增加工种那么在简单工厂的基础上我们只能通过修改CreateEmployee方法的实现细节不符合违背了开闭原则对象应该对扩展开放修改封闭那么我们使用工厂方法将对象的创建方法下发到子类工厂中 public abstract class Department // 父类工厂 {public abstract Employee CreateEmployee(); }public class ITDepartment : Department // 程序员工厂 {public override Employee CreateEmployee(){return new Programmer();} }public class UIDepartment : Department // 设计师工厂 {public override Employee CreateEmployee(){return new Designer();} }创建方法调用通过使用不同的子类工厂来完成创建这样扩展新工种时只需要创建类和子类工厂 ITDepartment itDepartment new ITDepartment(); itDepartment.CreateEmployee(); UIDepartment uiDepartment new UIDepartment(); uiDepartment.CreateEmployee();2.创建模板方法 如果这个时候需要对每个新创建的员工都实现一个注册账户的方法可以发现从创建对象到注册的业务执行是固定的但是每一个接口所对应的具体实现不同 加入注册方法 public abstract class Employee // 工种父类 {public abstract string RegisterAccount(); // 注册方法 }public class Programmer : Employee // 程序员类 {public override string RegisterAccount(){return IT Random.Range(0, 100);}}public class Designer : Employee // 设计师类 {public override string RegisterAccount(){return UI Random.Range(100, 200);} } 实现父类工厂中的模板方法 public abstract class Department // 部门抽象类 {protected abstract Employee CreateEmployee();public Employee Onboard(){employee CreateEmployee(); // 具体实现通过子类employee.RegisterAccount();return employee;} }创建方法调用 ITDepartment itDepartment new ITDepartment(); itDepartment.Onboard();UIDepartment uiDepartment new UIDepartment(); uiDepartment.Onboard();抽象工厂Abstract Factroy 加入程序员有程序项目设计师有设计项目使用抽象工厂 public abstract class Project // 项目父类 {public abstract void AssignTo(); // 项目接口 }public class ITProject : Project // 程序项目类 {public override void AssignTo(){Debug.Log(Assign an IT to project);} }public class UIProject : Project // 设计师项目类 {public override void AssignTo(){Debug.Log(Assign an UI to project);} }重构部门抽象类加入项目类 public abstract class Department // 部门抽象类 {public abstract Employee CreateEmployee();public abstract Project CreateProject(); } public class ITDepartment : Department {public override Employee CreateEmployee(){return new Programmer();}public override Project CreateProject(){return new ITProject();}}public class UIDepartment : Department {public override Employee CreateEmployee(){return new Designer();}public override Project CreateProject(){return new UIProject();} }创建工厂管理类实现一对多的关系例如一个程序员部门可以有多个项目多个员工 // 工厂管理类 public class DepartManager {private Department _department;public ListProject _projects;public Dictionarystring, Employee _employees;public DepartManager(Department department){_department department;}public Project CreateProject(){if (_projects null) _projects new ListProject();Project project _department.CreateProject();_projects.Add(project);return project;}public string CreateEmployee(){if (_employees null) _employees new Dictionarystring, Employee();Employee employee _department.CreateEmployee();string accountNo employee.RegisterAccount();_employees.Add(accountNo, employee);return accountNo;} }方法调用 DepartManager itDepManager new DepartManager(new ITDepartment()); itDepManager.CreateProject(); itDepManager.CreateEmployee();DepartManager uiDepManager new DepartManager(new UIDepartment()); itDepManager.CreateProject(); itDepManager.CreateEmployee();策略模式
http://www.hkea.cn/news/14382910/

相关文章:

  • 网站开发工作流审批流网站开发摊销年限
  • 免费行情软件网站下载淮南本地网
  • 商家入驻网站建设做网站游戏推广赚钱
  • 男女做暖暖网站什么是域名解析服务
  • 网站开发要求有哪些如何下wordpress
  • 搭建网站要哪些知识seo网络推广外包公司
  • 江门网站制作费用石家庄局域网网站建设
  • 网站seo外链建设wordpress 外部链接
  • 宿迁做网站的制作类网站
  • 上海建网站公司前几年做那些网站致富
  • 温州网站建设方案书网站简单设计
  • 关于做花茶网站的策划书嘉峪关建设厅官方网站
  • 深圳 手机网站做链接哪个网站好
  • 有哪些网站可以免费的wordpress 新页面打开空白
  • 江苏省省建设集团网站怎么开发属于自己的app软件
  • 网站建设硬件支撑怎么介绍自己做的电影网站
  • 校园网站建设培训班空白网站建设
  • ppt做的最好的网站有哪些网站建设图片改不了
  • 云梦网站建设欧美一级a做爰片免费网站
  • 做视频网站 视频放在哪里找wordpress d8 4.0
  • 手机怎样使用域名访问网站seo研究中心怎么了
  • 网站开发商务合同郑州高端设计公司
  • 铁岭网站seo婚庆影楼型网站开发
  • 做外贸需要自己建网站吗即时设计怎么做网页
  • 白色网站源码wordpress文章签名插件
  • 山东省建设银行网站建设领域现场专业人员报名网站
  • wordpress 网站白屏wordpress模板安装后效果和预览不同
  • 潍坊公司注册网站医疗器械一类二类三类
  • 网站建设公司该如何选择wordpress 扩展
  • 自己怎么弄网站德阳网站怎么做seo