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

做柜子喜欢上哪些网站看如何提升网站排名

做柜子喜欢上哪些网站看,如何提升网站排名,哪个推客平台最好,建一个门户网站设计模式六大原则是单一职责原则、里氏替换原则、依赖倒置原则、接口隔离原则、迪米特法则、开闭原则。它们不是要我们刻板的遵守,而是根据实际需要灵活运用。只要对它们的遵守程度在一个合理的范围内,努为做到一个良好的设计。本文主要介绍一下.NET(C#)…

设计模式六大原则是单一职责原则、里氏替换原则、依赖倒置原则、接口隔离原则、迪米特法则、开闭原则。它们不是要我们刻板的遵守,而是根据实际需要灵活运用。只要对它们的遵守程度在一个合理的范围内,努为做到一个良好的设计。本文主要介绍一下.NET(C#) 迪米特法则。

 

迪米特法则(Law Of Demeter)

迪米特法则(Law of Demeter)又叫作最少知识原则(The Least Knowledge Principle),一个类对于其他类知道的越少越好,就是说一个对象应当对其他对象有尽可能少的了解,只和朋友通信,不和陌生人说话。迪米特法则的初衷在于降低类之间的耦合。由于每个类尽量减少对其他类的依赖,因此,很容易使得系统的功能模块功能独立,相互之间不存在(或很少有)依赖关系。

迪米特法则不希望类之间建立直接的联系。

例如,

1)一般的反面设计实现

using System;
using System.Collections.Generic;
namespace ConsoleApplication
{//学校总部员工类class Employee{public string Id { get; set; }}//学院的员工类class CollegeEmployee{public string Id { get; set; }}//管理学院员工的管理类class CollegeManager{//返回学院的所有员工public List<CollegeEmployee> getAllEmployee(){List<CollegeEmployee> list = new List<CollegeEmployee>();//增加了10个员工到listfor (int i = 0; i < 10; i++){CollegeEmployee emp = new CollegeEmployee();emp.Id="学院员工ID=" + i;list.Add(emp);}return list;}}//学校管理类class SchoolManager{//返回学校总部的员工public List<Employee> getAllEmployee(){List<Employee> list = new List<Employee>();for (int i = 0; i < 5; i++){Employee emp = new Employee();emp.Id = "学校总部员工ID=" + i;list.Add(emp);}return list;}//该方法完成输出学校总部和学院员工信息(ID)public void PrintAllEmployee(CollegeManager sub){//CollegeEmployee不是SchoolManager的直接朋友//CollegeEmployee是以局部变量方式出现在SchoolManager违反了迪米特法则//获取学院员工List<CollegeEmployee> list1 = sub.getAllEmployee();Console.WriteLine("===========学院员工==============");foreach (CollegeEmployee e in list1){Console.WriteLine(e.Id);}//获取学院总部员工List<Employee> list2 = this.getAllEmployee();Console.WriteLine("===========学院总部员工==============");foreach (Employee e in list2){Console.WriteLine(e.Id);}}}class Program{static void Main(string[] args){//创建一个SchoolManager对象SchoolManager schoolManager = new SchoolManager();//输出学院的员工ID和学校总部的员工信息schoolManager.PrintAllEmployee(new CollegeManager());Console.ReadKey();}}
}

 2)迪米特法则的实现

using System;
using System.Collections.Generic;
namespace ConsoleApplication
{//学校总部员工类class Employee{public string Id { get; set; }}//学院的员工类class CollegeEmployee{public string Id { get; set; }}//管理学院员工的管理类class CollegeManager{//返回学院的所有员工public List<CollegeEmployee> getAllEmployee(){List<CollegeEmployee> list = new List<CollegeEmployee>();//增加了10个员工到listfor (int i = 0; i < 10; i++){CollegeEmployee emp = new CollegeEmployee();emp.Id = "学院员工ID=" + i;list.Add(emp);}return list;}//输出学院员工的信息public void printEmployee(){//获取到学院员工List<CollegeEmployee> list1 = getAllEmployee();Console.WriteLine("===========学院员工==============");foreach (CollegeEmployee e in list1){Console.WriteLine(e.Id);}}}//学校管理类class SchoolManager{//返回学校总部的员工public List<Employee> getAllEmployee(){List<Employee> list = new List<Employee>();for (int i = 0; i < 5; i++){Employee emp = new Employee();emp.Id = "学校总部员工ID=" + i;list.Add(emp);}return list;}//该方法完成输出学校总部和学院员工信息(ID)public void PrintAllEmployee(CollegeManager sub){//将输出学院员工方法,封装到CollegeManagersub.printEmployee();//获取学院总部员工List<Employee> list2 = this.getAllEmployee();Console.WriteLine("===========学院总部员工==============");foreach (Employee e in list2){Console.WriteLine(e.Id);}}}class Program{static void Main(string[] args){//创建一个SchoolManager对象SchoolManager schoolManager = new SchoolManager();//输出学院的员工ID和学校总部的员工信息schoolManager.PrintAllEmployee(new CollegeManager());Console.ReadKey();}}
}

 

http://www.yayakq.cn/news/356007/

相关文章:

  • 国家建设局网站首页静态网站论文目录
  • 新手学做网站txt中国十大门户网站排行
  • 私人定制哪个网站做的比较好登录百度账号
  • 建设部规范网站重庆企业型网站建设
  • 网站开发南城科技大厦网站建设维护职责
  • 哈尔滨优质的建站销售价格怎样做免费网站建设
  • 淄博网站建设服务商wordpress支付通道
  • 织梦网站定制电商赚钱吗
  • 北京保障房建设网站做编程的+网站有哪些内容
  • 各个做网站的有什么区别培训中心网站建设
  • 网站首页被k还有救吗站长工具网
  • 网站制作推广方案wordpress引用js代码
  • 2345网址导航下载到桌面单页站好做seo吗
  • 计算机应用教程 网站的建设与维护网站建设信息
  • 做外贸网站建设如何做免费网站
  • 网站优化查询北戴河网站建设
  • 怎样做不用备案的网站黑帽seo之搜索引擎
  • 美工怎么做网站效果图做网站一年大概的盈利
  • 怎么弄一个网站平台wordpress旅游
  • ins做甜品网站网站备案期间完全关闭么
  • 芜湖公司网站建设网站实现步骤及方法是
  • 想建书画网站怎么做的快速搭建网站前端插件
  • 做设计用的素材下载网站wordpress 图片暗箱插件
  • 广东专业网站定制网站后台功能需求文档
  • 照明网站模板网页制作教程用什么软件
  • 怎么做子网站wordpress主题官方购买
  • 做网站配置dede网站地图地睛
  • 电商网站如何做引流免费文字一键生成图片
  • 成功网站建设案例沙田镇网站建设公司
  • 抖音点赞自助网站电脑零基础培训学校