善知堂android学习笔记

java(学习笔记第九天)

回顾:
 递归
 冒泡排序
 单例
 泛型


接口的应用:
 1、定义操作标准
 2、表达一种能力
 3、将远程方法暴露给远程客户端。

例子:
接口=》1调用接口=》实现接口=》调用方法1

抽象类:
  抽象类{
   内部抽象类
   内部接口
  }
接口{
 内部抽象类
 内部方法
 内部接口
}
 

*接口应用(一):表示工场设计模式
  public abstract class Fruit{
   String name;
   public abstract String getName();
  }
 class Apple extends Fruit{
  ...
 }
 class Orange extends Fruit{
  ...
 }
  class FruitFactory{
     public static Fruit getFruit(String str){
       if(str.equals("apple")){
           return new Apple();
       }else if(str.equals("orange")){
            return new Orange();
       }else{
        return null;
       }
     }
  }


//运行代码
main{
Fruit f=FruitFactory.getFruit(args[])
syso(args[0]);
}


*接口应用(二):代理设计模式 (++++++++++++)

  在功能的实现者上附加一些功能

 
*接口应用(三):适配器模式


*匿名内部类
 
  new 出来的即使对象,也是匿名内部类
 

  public class animal{
       public void walk(){
       }
  }
  class Dog extends animal{
  }
  class cat extends animal{
  }

  public class Main{
   static main(String args[]){
      animal a=new Dog();
      //new Main().showAnimal(a);
       new Main().showAnimal(new animal(){//匿名内部类
          public void walk(){
             
          }
       });
     }
    public void show Animal(animal a)
    {
      animal.walk();
    }
  }
*包装类(封装类)//自动拆箱装箱

http://itszt.losoon.com/a/xueyuanxinde/2012/0326/244.html

posted on 2012-03-26 19:48  筱石头丶莜  阅读(97)  评论(0)    收藏  举报

导航

善知堂网址http://itszt.losoon.com