1. Write a singleton class.
// The first form: hungry Chinese singleton public class Singleton { private Singleton(){} private static Singleton instance = new Singleton(); public static Singleton getInstance(){ return instance; } } // The second form: lazy singleton public class Singleton { private static Singleton instance = null; private Singleton() {} public static synchronized Singleton getInstance(){ if (instance==null) instance=newSingleton(); return instance; } }
2. Tell us about the design patterns you are familiar with or heard of and what design patterns have you used in your development?
Creation type: simple factory, factory method, abstract project, builder mode, singleton, prototype(clone)
Structural Types: Adapter, Decorator, Bridge, Facade, Composition, Proxy Mode
Behavioral: command pattern, observer, strategy pattern, template, state pattern, iterator pattern, memo pattern