为了执行这项重构,必须首先使用Replace Type Code with Subclasses 或者Replace Type Code with State/Strategy。 即使,不存在根据它的值而执行不同的行为,但是有些行为还是比较适合放在Type Code Class中,所以要判断是否要使用Move Method进行行为的搬移。 作法: 1. 为type code
一般两个特征总是必不可少,getState, setSate。 进一步,因为类型码是有限可列举的,所以setState最好是可以使用HashMap实现,static Hashmap<typecode, class>. over 完整的重构代码包here下载
13.Replace Type Code With Class(以类取代型别码) class之中有一个数值型别码,但它不影响class的行为。以一个新的class替换该数值型别码。 Example: classPerson{publicstaticfinalintO=0;publicstaticfinalintA=1;publicstaticfinalintB=2;publicstaticfinalintC=3;privateint_bloodGroup;publicPerson(intbloodGrou...
重构第八章 14.Replace Type Code With Subclasses(以子类取代型别码) 你有一个不可变的type code,它会影响class的行为。以一个subclass取代这个type code。 Example: classEmployee...privateint_type;staticfinalintENGINEER=0;staticfinalintSALESMAN=1;staticfinalintMANAGER=2;Employee(inttype){_type=type;} E...
一道Leetcode上的题目: Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine...if the input string is valid...有两个解法 解法一:class Solution {public: bool isValid(string s) { stackchar> paren; for (char...for (char& c : s)...
The following example shows a type that violates this rule. C# 複製 using System; namespace DesignLibrary { public class BadRepeatArguments { // Violates rule: ReplaceRepetitiveArgumentsWithParamsArray. public void VariableArguments(object obj1, object obj2, object obj3, object obj4) {} public...
$("div.second").replaceWith("<h2>New heading</h2>"); This results in the structure: 1 2 3 4 5 <divclass="container"> <divclass="inner first">Hello</div> <h2>New heading</h2> <divclass="inner third">Goodbye</div> </div> ...
<button class="ms-Button" id="insert-image">Insert Image</button><br/><br/> Open the file ./src/taskpane/taskpane.js. Locate the Office.onReady() method call near the top of the file and add the following code immediately before that line. This code imports the variable that you...
using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string input = "This is text with far too much " + "white space."; string pattern = "\\s+"; string replacement = " "; Regex rgx = new Regex(pattern); string result = rgx.Replace...
* @param exposureLevel can be any of the <code>EXPOSE_xxx</code> * constants. */ public void setExposureLevel(int exposureLevel) { checkModifiable(); if (classIntrospector.getExposureLevel() != exposureLevel) { ClassIntrospectorBuilder builder = classIntrospector.createBuilder(); builder.setEx...