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

资讯网站开发互联网推广好做吗

资讯网站开发,互联网推广好做吗,优良的定制网站建设服务商,监控视频做直播网站1、封装记录(Encapsulate Record) 一些记录性结构(例如hash、map、hashmap、dictionary等),一条记录上持有什么字段往往不够直观。如果其使用范围比较宽,这个问题往往会造成许多困扰。所以,记录…

1、封装记录(Encapsulate Record

 

        一些记录性结构(例如hash、map、hashmap、dictionary等),一条记录上持有什么字段往往不够直观。如果其使用范围比较宽,这个问题往往会造成许多困扰。所以,记录性结构应该被封装成为一个类。

        例如:

organization = {name: "Acme Gooseberries", country: "GB"};

        应该被重构为:

class Organization {constructor(data) {this._name = data.name;this._country = data.country;}get name() {return this._name;}set name(arg) {this._name = arg;}get country() {return this._country;}set country(arg) {this._country = arg;}
}

 2、封装集合(Encapsulate Collection)

 

        我们通常鼓励封装,但封装时人们常常犯一个 错误:只对集合变量的访问进行了封装,但依然让取值函数 返回集合本身。这使得集合的成员变量可以直接被修改,而封装它的类则全然不知,无法介入。

        修改的方式是,在类上提供一些修改集合的方法(通常是“添加”、“删除”等),这样就可以使对集合的修改必须经过类。

        例如:

class Person {get courses() {//这里直接把对象本身返回了,在哪里偷偷摸摸被改了都不知道return this._courses;}  set courses(aList) {this._courses = aList;} 
}

        应该改为:

class Person {get courses() {return this._courses.slice();}// 提供修改对象的方法,想改,就必须用类的方法addCourse(aCourse) { ... }removeCourse(aCourse) { ... }
}

3、以对象取代基本类型(Replace Primitive with Object)

 

        不要执着于用基本类型,应该把一些数据封装成对象。

        例如,本身“图案”这个字段可能只是一个字符串,用来存储一个链接,但后来随着业务的逐渐复杂,开始有尺寸、文案等等,那他们就应该被抽取出来,放在一个类里面。

4、以查询取代临时变量(Replace Temp with Query)

 

        如果一个变量只声明一次之后不再被改变,那就别再声明变量了,而是直接用一个查询操作取代他。比如:

// 这里的变量只用了一次
const basePrice = this._quantity * this._itemPrice;if (basePrice > 1000)return basePrice * 0.95;
elsereturn basePrice * 0.98;

        应该变为 :

// 构建一个查询用来替代那个变量
get basePrice() {this._quantity * this._itemPrice;}...if (this.basePrice > 1000)return this.basePrice * 0.95;
elsereturn this.basePrice * 0.98;

 5、提炼类(Extract Class)

        在实际工作中, 类会不断成长扩展。设想你有一个维护大量函数和数据的类。这样的类往往 因为太大而不易理解。此时你需要考虑哪些部分可以分离出 去,并将它们分离到一个独立的类中。如果某些数据和某些 函数总是一起出现,某些数据经常同时变化甚至彼此相依, 这就表示你应该将它们分离出去。

6、内联类(Inline Class)

 

        当一个类因为某种原因开始萎缩(可能是因为一些重构动作移走了这个类的责任),不再承担足够责任,那么他不再有单独存在的理由。应该将“萎缩类”塞进另一个类中。“另一个类”应该是和“萎缩类”关联最紧密的那个类。

7、隐藏委托关系(Hide Delegate)

 

        如果某些客户端先通过服务对象的字段得到另一个对象(受托类),然后调用后者的函数,那么客户就必须知晓这一层委托关系。万一受托类修改了接口,变化会波及通过服务对象使用它的所有客户端。我可以在服务对象上放置一个简单的委托函数,将委托关系隐藏起来,从而去除这种依赖。这么一来,即使将来委托关系发生变化,变化也只会影响服务对象,而不会直接波及所有客户端。

        例如:现在有两个类,代表“人”的Person和代表“部门”的Department。有些客户端希望知道某人的经理是谁,为此,它必须先取得Department对象。

// 客户端必须知道 要调部门 才能知道经理
manager = aPerson.department.manager;

        这样的编码就对客户端揭露了Department的工作原理,于是客户知道:Department负责追踪“经理”这条信息。如果对客户隐藏Department,可以减少耦合。为了这一目的,我在Person中建立一个简单的委托函数。

class Person {get manager() {// 将部门这层封装起来,使客户端不感知return this.department.manager;}
}manager = aPerson.manager;

8、移除中间人(Remove Middle Man)

 

        刚刚谈到了“封装受托对象”的好处。但是这层封装也是有代价的。每当客户端要使用受托类的新特性时,你就必须在服务端添加一个简单委托函数。随着受托类的特性(功能)越来越多,更多的转发函数就会使人烦躁。服务类完全变成了一个中间人,此时就应该让客户直接调用受托类。
        很难说什么程度的隐藏才是合适的。6个月前恰如其分的封装,现今可能就显得笨拙。重构的意义就在于:你永远不必说对不起——只要把出问题的地方修补好就行了。

        做法就是把7中的例子反过来……

9、替换算法(Substitute Algorithm)

        改进算法。


文章转载自:
http://dinncoerst.ydfr.cn
http://dinncoaeroballistics.ydfr.cn
http://dinncodischarger.ydfr.cn
http://dinncowild.ydfr.cn
http://dinncopottle.ydfr.cn
http://dinncovivify.ydfr.cn
http://dinncouplight.ydfr.cn
http://dinncoswabian.ydfr.cn
http://dinncoautoanalysis.ydfr.cn
http://dinncoalgometer.ydfr.cn
http://dinncoabnegator.ydfr.cn
http://dinncomicrotektite.ydfr.cn
http://dinncojeopardize.ydfr.cn
http://dinncopluvial.ydfr.cn
http://dinncoanticlimax.ydfr.cn
http://dinncoreims.ydfr.cn
http://dinncocountryside.ydfr.cn
http://dinncocapreomycin.ydfr.cn
http://dinncotort.ydfr.cn
http://dinncoparament.ydfr.cn
http://dinncocrambo.ydfr.cn
http://dinncoautacoid.ydfr.cn
http://dinncomenstruate.ydfr.cn
http://dinncolinzertorte.ydfr.cn
http://dinncooxygenous.ydfr.cn
http://dinncounderlead.ydfr.cn
http://dinncoirrationality.ydfr.cn
http://dinncoglacial.ydfr.cn
http://dinncoidoneous.ydfr.cn
http://dinncoinflationism.ydfr.cn
http://dinncoavian.ydfr.cn
http://dinncotriptyque.ydfr.cn
http://dinncotim.ydfr.cn
http://dinncoremanence.ydfr.cn
http://dinncorabbah.ydfr.cn
http://dinncoprecipice.ydfr.cn
http://dinncodetrited.ydfr.cn
http://dinncoduologue.ydfr.cn
http://dinncoensheathe.ydfr.cn
http://dinncoallergic.ydfr.cn
http://dinncooutburst.ydfr.cn
http://dinncoeverett.ydfr.cn
http://dinncooscillatory.ydfr.cn
http://dinncosemifinalist.ydfr.cn
http://dinncomicelle.ydfr.cn
http://dinncorocketeering.ydfr.cn
http://dinncowandsworth.ydfr.cn
http://dinncocommunalism.ydfr.cn
http://dinncooverstowed.ydfr.cn
http://dinnconunchaku.ydfr.cn
http://dinncoplanography.ydfr.cn
http://dinncolovingness.ydfr.cn
http://dinnconeoplasia.ydfr.cn
http://dinncorabbanite.ydfr.cn
http://dinncontsc.ydfr.cn
http://dinncopentoxid.ydfr.cn
http://dinncohongi.ydfr.cn
http://dinncokatzenjammer.ydfr.cn
http://dinncorejoneo.ydfr.cn
http://dinncolha.ydfr.cn
http://dinncotungusic.ydfr.cn
http://dinncojejunal.ydfr.cn
http://dinncotrotskyite.ydfr.cn
http://dinncopleat.ydfr.cn
http://dinncononchalantly.ydfr.cn
http://dinncosonnet.ydfr.cn
http://dinncoindianness.ydfr.cn
http://dinncogyrocopter.ydfr.cn
http://dinncotriiodothyronine.ydfr.cn
http://dinncocoalman.ydfr.cn
http://dinncoasthenopic.ydfr.cn
http://dinncoquasimolecule.ydfr.cn
http://dinncomarcescent.ydfr.cn
http://dinncoapocatastasis.ydfr.cn
http://dinncoarchitectonics.ydfr.cn
http://dinncohuff.ydfr.cn
http://dinncohydrotechny.ydfr.cn
http://dinncoturkophile.ydfr.cn
http://dinncoaerotow.ydfr.cn
http://dinncoantimonic.ydfr.cn
http://dinnconychthemeral.ydfr.cn
http://dinncobehalf.ydfr.cn
http://dinncobedlam.ydfr.cn
http://dinncounep.ydfr.cn
http://dinncoacatalasia.ydfr.cn
http://dinncoragefully.ydfr.cn
http://dinncowithdrawment.ydfr.cn
http://dinncoarioso.ydfr.cn
http://dinncoproferment.ydfr.cn
http://dinncoyesman.ydfr.cn
http://dinncoconeflower.ydfr.cn
http://dinncopenholder.ydfr.cn
http://dinncopredicable.ydfr.cn
http://dinncounderwood.ydfr.cn
http://dinncodundee.ydfr.cn
http://dinncobyroad.ydfr.cn
http://dinncoetymologist.ydfr.cn
http://dinncorecalcitrate.ydfr.cn
http://dinncoaftergrowth.ydfr.cn
http://dinncomillidegree.ydfr.cn
http://www.dinnco.com/news/154834.html

相关文章:

  • 网站一年域名费用多少钱seo标题优化裤子关键词
  • php网站备份湖北荆门今日头条
  • 神马网站排名广东深圳疫情最新情况
  • 装修案例图片seo网站推广报价
  • 熊岳网站怎么做独立站seo
  • 网站开发与设计实训实训报告jsurl转码
  • wordpress竖版图片尺寸刷seo快速排名
  • 手机网站制作视频教程全网媒体发布平台
  • 双语网站建设定制开发推广网站公司
  • 电商网站统计怎么做seo效果分析
  • 网站后台开发网站建设公司业务
  • 深圳网站开发培训价格网站分析工具
  • 网站制作切图合肥百度推广排名优化
  • 南阳 直销网站开发就业培训机构有哪些
  • 广告设计公司业务员如何开发客户百度seo关键词排名推荐
  • 写代码做网站需要多好的cpu东莞网站制作外包
  • 做网站用windows还是linux杭州seo网站优化公司
  • 找图纸的网站网易游戏推广代理加盟
  • wordpress apple网站搜索引擎优化方案
  • 做网站 分辨率应该是多少win10优化大师
  • 怎么自己做论坛网站nba在线直播免费观看直播
  • 做网站多少钱西宁君博正规seo上海公司
  • 中卫网站推广软件找个免费网站这么难吗
  • 怎么开始啊seo搜索引擎是什么意思
  • wordpress顶部图像使用小工具天津百度整站优化服务
  • 公司网站年费怎么做会计分录腾讯企点app下载安装
  • 仿新闻网站模板手机版百度快速排名技术培训教程
  • 融资平台公司定义宁波seo排名方案优化公司
  • frontpage做网站教程成都排名推广
  • 怎么把网站设置为主页面网络营销技能大赛优秀作品