摘要: 面向对象程序的一个最明显特征就是:少用switch或(case)语句。 从本质上说,switch语句的问题在于重复。 你常会发现switch语句散布于不同地点。如果要为它添加一个新的case子句,就必须找到所有switch语句并修改它们。 面向对象中的多态概念可为此带来优雅的解决办法。 大多数时候, 阅读全文
posted @ 2018-02-07 19:29 Sharpest 阅读(430) 评论(0) 推荐(0) 编辑
摘要: 你有一个数组(array),其中的元素各自代表不同的东西。 以对象替换数组。对于数组中的每个元素,以一个值域表示之。 String[] row = new String[3]; row [0] = "Liverpool"; row [1] = "15"; Performance row = new 阅读全文
posted @ 2018-02-07 19:04 Sharpest 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 你有一个type code ,它会影响class 的行为,但你无法使用subclassing。 以state object (专门用来描述状态的对象)取代type code 。 动机(Motivation) 本项重构和Replace Type Code with Subclasses 很相似,但如果 阅读全文
posted @ 2018-02-07 18:42 Sharpest 阅读(402) 评论(0) 推荐(0) 编辑
摘要: 你有一个不可变得type code,它会影响类的行为。 以一个子类取代这个type code。 动机 如果一个type code不会影响行为,你可以使用Replace Type Code with Class;但是,如果一个type code会影响行为,最好的办法就是借助多态来处理变化的行为。 一般 阅读全文
posted @ 2018-02-07 17:27 Sharpest 阅读(297) 评论(0) 推荐(0) 编辑
摘要: 转自:https://blog.csdn.net/u012560212/article/details/75037578 阅读全文
posted @ 2018-02-07 15:13 Sharpest 阅读(1266) 评论(0) 推荐(0) 编辑
摘要: class 中有一个数值型别码,但它不影响class的行为 以一个新的class替换该数值型别码。 class Person ...public static final int O = 0;public static final int A = 1;public static final int 阅读全文
posted @ 2018-02-07 12:13 Sharpest 阅读(323) 评论(0) 推荐(0) 编辑
摘要: 你有一笔数据项(data item),需要额外的数据和行为。 将这笔数据项变成一个对象。 class Order... private string customer; ==> class Order... private Customer _customer; class Customer...  阅读全文
posted @ 2018-02-07 10:37 Sharpest 阅读(282) 评论(0) 推荐(0) 编辑
摘要: 对象技术的新手通常不愿意在小任务上运用小对象—像是结合数值和币种的money类,由一个起始值和结束值组成的range类等。你可以使用 Replace Data Value with Object (以对象取代数据值)将原本单独存在的数据值替换为对象。如果想要替换的数据值是类型码,而它并不影响行为,则 阅读全文
posted @ 2018-02-07 10:35 Sharpest 阅读(1800) 评论(0) 推荐(0) 编辑