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 閱讀(228) 評論(0)  編輯  收藏

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


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

          常用鏈接

          留言簿(1)

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 金坛市| 昂仁县| 桃源县| 天长市| 闵行区| 育儿| 淮滨县| 成安县| 平邑县| 浠水县| 五大连池市| 枝江市| 临汾市| 乡宁县| 南开区| 乌苏市| 法库县| 读书| 黔江区| 文山县| 博兴县| 全南县| 大城县| 镶黄旗| 三穗县| 淄博市| 陵水| 留坝县| 孙吴县| 呈贡县| 阳谷县| 洛隆县| 贵阳市| 襄垣县| 庆云县| 长顺县| 英吉沙县| 清新县| 广灵县| 全椒县| 金寨县|