The Factory pattern provides a way to use an instance as a object factory.The factory can return an instance of one of several possible classes(in a subclass hierarchy),depending on the date provided to it.

阅读全文 »

Strategy Pattern

What’s the Strategy Pattern ?
In the Wiki:

  • defines a family of algorithms,
  • encapsulates each algorithm
  • makes the algorithms interchangeable within that family.
阅读全文 »

Java-Autoboxing-and-Unboxing

Autoboxing and unboxing is introduced in Java1.5 to automatically convert primitive type into boxed primitive(Object or Wrapper class).Autoboxing allows you to use primitive and object type interchangeably in Java on many place like assignment,method invocation.

阅读全文 »

Java Reflection

“Reflection is commonly used by programs which require the ability to examine or modify the runtime behavior of applications running in Java Virtual machine.” The concept is ofen mixed with introspecion.The following are their definitions from Wiki:

阅读全文 »

Avoid “magic numbers”

Code Complete》 SAYS:

Magic numbers are literal numbers such as 100 or 47524 that appear in the middle of a program without explanation.If your program in a language that supports named constants,use them instead.If you can’t use named constants,use global variables when it is feasible to.

阅读全文 »

多态

多态是继数据抽象和继承之后的第三种基本特征

多态通过分离做什么怎么做。多态不但能过改善代码额组织结构和可读性,还能够创建可扩展的程序——无论什么时候,需要新功能的时候都能添加。多态的作用是消除类型的耦合关系(耦合:对象之间的依赖性,对象之间耦合度越高,维护成本越高。)

阅读全文 »