锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
open close principle寮闂師鍒?br />liskov substitution principle閲屾皬鏇挎崲鍘熷垯
Low of Demete榪背鐗規硶鍒?br />interface segregation principle鎺ュ彛闅旂鍘熷垯
dependence inversion principle渚濊禆鍊掔疆鍘熷垯
SOLID
寮闂師鍒欙細
public interface IBook{
public String getName();
public int getPrice();
public String getAuthor();
}
===================================================
灝忚涔︾睄鐨勬簮浠g爜濡備笅錛?br />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,"閲戝焊"))錛?br />bookList.add(new NovelBook("澶╅緳鍏儴2",3200,"閲戝焊"))錛?br />bookList.add(new NovelBook("澶╅緳鍏儴3",3200,"閲戝焊"))錛?br />bookList.add(new NovelBook("澶╅緳鍏儴4",3200,"閲戝焊"))錛?/p>
}
public static void main(Sting() args){
NumberFormat formatter=NumberFormat2.getCurrencyInstance();
formatter.setMaximunFractionDigits(2);
System.out.println("--------------涔﹀簵涔板嚭鍘葷殑涔︾睄濡備笅")錛?br /> for(IBook book:bookList){
book.getName();
book.getAuthor();
book.getPrice();
}
}
}