1、面向对象设计原则
2、单例
/**
* 饿汉式:对象的初始化过程在类加载的时候就已经完成
* 在开发中建议使用
* @author luo
*
*/
public classConfiguration {
private static Configuration conf = new Configuration();
public static Configuration getInstance(){
return conf;
}
privateConfiguration(){
}
}
/**
* 懒汉式:调用方法的时候再创建使用
* 在面试中建议使用
* @author luo
*
*/
public classConfiguration {
private static Configuration conf = null;
public static synchronized Configuration getInstance(){
if(conf ==null){
conf = newConfiguration();
}
return conf;
}
privateConfiguration(){
}
}
3、工厂模式
4、包装设计模式
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class MyBufferedReader extends BufferedReader{
private BufferedReader br ;
private int number= 1;
public MyBufferedReader(BufferedReader br){
super(br);
this.br = br;
}
public String readLine() throws IOException{
if(br.readLine() == null)
return null;
return number+++br.readLine();
}
public static void main(String[] args) throws Exception {
MyBufferedReader reader = new MyBufferedReader(new BufferedReader(new FileReader("d://giftsstore.log")));
String line = null;
while((line=reader.readLine()) != null){
System.out.println(line);
}
}
}