posts - 6,  comments - 7,  trackbacks - 0
          interfaces

          上午完成thinking Java中關于Interfaces章節的內容。下面是該章節中關于"Interfaces and factories"的例子
          package com.zhanjh.thinkingjava.interfaces;

          interface Service{
              void method1();
              void method2();
          }

          interface ServiceFactory{
              Service getService();
          }

          class Implementation1 implements Service{
              public Implementation1() {
                  // TODO Auto-generated constructor stub
              }
             
              public void method1(){
                  System.out.println("Implementation1 method1");
              }
              public void method2(){
                  System.out.println("Implementation1 method2");
              }
          }

          class Implementation1Factory implements ServiceFactory{
              public Service getService(){
                  return new Implementation1();
              }
          }

          class Implementation2 implements Service{
              public Implementation2() {
                  // TODO Auto-generated constructor stub
              }
             
              public void method1(){
                  System.out.println("Implementation2 method1");
              }
              public void method2(){
                  System.out.println("Implementation2 method2");
              }
          }

          class Implementation2Factory implements ServiceFactory{
              public Service getService(){
                  return new Implementation2();
              }
          }

          public class Factories{
              public static void serviceConsumer(ServiceFactory fact){
                  Service s=fact.getService();
                  s.method1();
                  s.method2();
              }
              public static void main(String[] args){
                  serviceConsumer(new Implementation1Factory());
                  serviceConsumer(new Implementation2Factory());
              }
          }
          總結:abstract class和interface是Java語言中對于抽象類定義進行支持的兩種機制,abstract class和interface之間在對于抽象類定義的支持方面具有很大的相似性。目前我對他們區分的方法大致如下:
          1)interface可以多重實現,而abstract class只能單一繼承
          2)abstract class不一定只有抽象的方法(abstract method),它也可以包含具體的方法(concrete method)。而interface不能包含方法的實現(implementation)。所以在程序設計的時候,能用inteface的時候盡量不要用abstract class。

          下午
               查找關于EJB的資料,沒頭緒。
               jaxb入門學習。
               xjc(將xsd文件轉換為Java的小工具)工具的使用。可以創建一個bat文件處理下面的命令:
              xjc -d "D:"eclipse"workspace"JaxbTest"src" -p "edu.jlu.xml" "D:"eclipse"workspace"JaxbTest"schema"messages.xsd"
          其中D:"eclipse"workspace"JaxbTest"src為原文件的目錄,edu.jlu.xml為生成Java類的包名,D:" eclipse"workspace"JaxbTest"schema"messages.xsd為xml schema文件的路徑。

          posted on 2007-12-26 19:07 zhan 閱讀(223) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2007年12月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          常用鏈接

          留言簿(1)

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 张家港市| 晋宁县| 科技| 定州市| 深州市| 乌拉特中旗| 闵行区| 富顺县| 昌宁县| 南召县| 连南| 阆中市| 瑞丽市| 建始县| 福建省| 山西省| 贡觉县| 罗田县| 商河县| 余庆县| 松溪县| 桃源县| 加查县| 遵化市| 新丰县| 三穗县| 时尚| 上栗县| 新宁县| 兴山县| 岐山县| 错那县| 囊谦县| 灵武市| 吐鲁番市| 宁城县| 曲麻莱县| 璧山县| 湖南省| 左云县| 高台县|