Java

Notes on ‘Refactoring ‘ — 3.3 Encapsulate Collection

Before Re-factoring class Person{ Set courses; Set getCourses(){ return courses; } void setCourses(){…} } After Re-factoring class Person{ Set courses; Set getCourses(){ return Collections.unmodifiableSet(courses); } void addCourse(){…} void removeCourse(){…} } Benefits: 1. Person will know it when courses changes. 2. Coupling between clients which call Person and courses will be reduced.

Notes on ‘Refactoring ‘ — 1. Principals

1. Definition by Martin Fowler    a.The purpose of refactoring is to make the software easier to understand and modify    b.Refactoring does not change the observable behavior of the software    2. Why Refactor? To make software easier to understand       a. You can refactor it to make it more readable for future developers …

Notes on ‘Refactoring ‘ — 1. Principals Read More »

Notes on ‘Refactoring ‘ — 2.1 Extract Method

When to do it?   There is a method that is too long, or some code in which needs a comment to understand its purpose Benefits    1. Finely grained sub-methods may be reusable in the future.    2. More readable. A series of sub-methods seem like a series of comments.

Notes on ‘Refactoring ‘ — 2.2 Replace Method with Method Object

When?    你有一个大方法要拆成若干个小方法。但这个大方法里有一大堆散乱的临时变量,并且它们被反复赋值,如果要拆分,就得传来传去,还要用做小方法的返回值,这样一搞代码的可读性不高。 Solution:   如果这些变量不是临时变量,而是成员变量,那么都不用传来传去,也不用用作小方法的返回值了。   然而,把这些变量用作当前对象的成员变量是不合适的。所以我们就新建一个类,然后把大方法放到这个类中,把临时变量用作这个类的成员变量,问题就解决了。

[Apache Commons]ToStringBuilder的几种ToStringStyle

老是记不住,干脆把它们抄到博客中来 1. DEFAULT_STYLE    Person@182f0db[name=John Doe,age=33,smoker=false] 2. MULTI_LINE_STYLE     Person@182f0db[    name=John Doe    age=33    smoker=false ] 3. NO_FIELD_NAMES_STYLE    Person@182f0db[John Doe,33,false] 4. SHORT_PREFIX_STYLE   Person[name=John Doe,age=33,smoker=false] 5. SIMPLE_STYLE    John Doe,33,false

[CXF] WSDLs2Java: 从一堆WSDL中一次性生成Java文件

目前CXF的 WSDL2JAVA 一次只能搞一个WSDL, 但一个项目中可能需要搞多个WSDL并打成一个JAR包。 下面的这个类就是帮助你从多个WSDL中生成一团JAVA文件。与ANT结合起来,可以得到更好的效果。 import java.util.ArrayList; import java.util.Arrays; import org.apache.cxf.tools.wsdlto.WSDLToJava; /** * Generate Java Codes from a number of WSDL files/urls <br/> * * @author chenjianjx * */ public class WSDLsToJava { /** * * @param args * The last args should be like "-wsdlList %wsdl1% %wsdl2% …" <br/> * The args between these …

[CXF] WSDLs2Java: 从一堆WSDL中一次性生成Java文件 Read More »