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();
}
}
}