2012年8月20日

          single responsibility principle單一職責(zé)原則
          open close principle開(kāi)閉原則
          liskov substitution principle里氏替換原則
          Low of Demete迪米特法則
          interface segregation principle接口隔離原則
          dependence inversion principle依賴(lài)倒置原則

          SOLID

          開(kāi)閉原則:

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

          }
          ===================================================
          小說(shuō)書(shū)籍的源代碼如下:
          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;}
          }

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

          銷(xiāo)售書(shū)籍:


          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("--------------書(shū)店買(mǎi)出去的書(shū)籍如下");
             for(IBook book:bookList){

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

          }


          }


          posted @ 2012-08-20 23:09 廖宏 閱讀(131) | 評(píng)論 (0)編輯 收藏
          僅列出標(biāo)題  

          導(dǎo)航

          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評(píng)論

          主站蜘蛛池模板: 曲阳县| 宣恩县| 比如县| 大埔区| 宜章县| 怀远县| 罗城| 甘德县| 乐清市| 青川县| 华阴市| 丹阳市| 北海市| 康乐县| 顺平县| 怀仁县| 句容市| 栾城县| 太和县| 舟山市| 富阳市| 密云县| 乌鲁木齐县| 鄂尔多斯市| 沅陵县| 青田县| 九江县| 秀山| 娄底市| 鄂尔多斯市| 伊通| 许昌县| 沈阳市| 保康县| 江源县| 绩溪县| 万盛区| 哈密市| 穆棱市| 福安市| 内乡县|