2012年8月20日

single responsibility principle单一职责原则
open close principle开闭原则
liskov substitution principle里氏替换原则
Low of Demete迪米特法则
interface segregation principle接口隔离原则
dependence inversion principle依赖倒置原则

SOLID

开闭原则:

public interface IBook{
  public String getName();
  public int getPrice();
  public String getAuthor();

}
===================================================
小说书籍的源代码如下:
public class NovelBook implements IBook{
private String name;

private int price;

private String author;

public NovelBook(String _name,int _price,String _author){

this.name=_name;
this.price=_price;
this.author=_author;
}

public String getAuthor(){
return this.author;}

public String getName(){
return this.name;}

public int getPrice(){
return this.price;}
}

}
========================================================

销售书籍:


public class BookStore{
private final static ArrayList<IBook> bookList= new ArrayList<IBook>();

static{
bookList.add(new NovelBook("天龙八部1",3200,"金庸"));
bookList.add(new NovelBook("天龙八部2",3200,"金庸"));
bookList.add(new NovelBook("天龙八部3",3200,"金庸"));
bookList.add(new NovelBook("天龙八部4",3200,"金庸"));

 

}

public static void main(Sting() args){
   NumberFormat formatter=NumberFormat2.getCurrencyInstance();
   formatter.setMaximunFractionDigits(2);
    System.out.println("--------------书店买出去的书籍如下");
   for(IBook book:bookList){

book.getName();
book.getAuthor();
book.getPrice();
}

}


}


posted @ 2012-08-20 23:09 廖宏 阅读(128) | 评论 (0)编辑 收藏
仅列出标题  

导航

<2024年10月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

统计

常用链接

留言簿

随笔档案

搜索

最新评论