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)

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 蕲春县| 宝山区| 通州市| 开原市| 江津市| 拉孜县| 堆龙德庆县| 古丈县| 清丰县| 灌南县| 察哈| 楚雄市| 开封县| 永清县| 黔江区| 乐昌市| 南开区| 鄢陵县| 曲麻莱县| 临朐县| 大姚县| 乡宁县| 会昌县| 荥经县| 黄龙县| 黄骅市| 龙井市| 蒙城县| 蓬安县| 合江县| 永善县| 中江县| 冕宁县| 英山县| 夏津县| 肃宁县| 岳池县| 靖安县| 融水| 高要市| 秦皇岛市|