用户操作
[即时聊天] [发私信] [加为好友]
cyhgohappyID:cyhgohappy
2907次访问,排名2万外,好友4人,关注者5人。
cyhgohappy的文章
原创 22 篇
翻译 0 篇
转载 10 篇
评论 10 篇
最近评论
hu437:这些Eclipse里面都有

如果NetBeans支持像VS一样的代码提示就好了,最起码希望能有像Eclipse一样的自己设置 代码提示的方法就好了
violy:好帖, 我白痴一点得问,用ftp 上传 图片 是怎么开始找资料的? 如果有api或者在官方网站上有学习资料就好了! 我都找不到,不知如何下手学! 只能在网上找找想你这样的文章! 这样实在是有点浮浅。有高贵一点的渠道获得吗?!
violy:好帖, 我白痴一点得问,用ftp 上传 图片 是怎么开始找资料的? 如果有api或者在官方网站上有学习资料就好了! 我都找不到,不知如何下手学! 只能在网上找找想你这样的文章! 这样实在是有点浮浅。有高贵一点的渠道获得吗?!
cyhgohappy:fu.ftpClient.sendServer("dele 2.txt "); //删除服务器上的文件

在MAIN方法中啊, 其实就是登陆服务器后,执行FTP的删除命令呀
cise2008sdust:连接成功的,到删除那就不响应了,提示
User logged in, proceed.
421
not disconnect
java.net.SocketException: Connection reset
文章分类
收藏
    相册
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 java-策略模式收藏

    新一篇: 客户端存储数据工具库-PersistJS | 旧一篇: Logger的简单使用

     
    1. 策略模式,又叫算法簇模式,就是定义了不同的算法族,并且之间可以互相替换,此模式让算法的变化独立于使用算法的客户。 
    2. 策略模式的好处在于你可以动态的改变对象的行为。 
    3. 设计原则是把一个类中经常改变或者将来可能改变的部分提取出来,作为一个接口(c++z中可以用虚类),然后在类中包含这个对象的实例,这样类的实例在运行时就可以随意调用实现了这个接口的类的行为。下面是一个例子。 
    4. 策略模式属于对象行为型模式,主要针对一组算法,将每一个算法封装到具有共同接口的独立的类中,从而使得它们可以相互替换。策略模式使得算法可以在不影响到客户端的情况下发生变化。通常,策略模式适用于当一个应用程序需要实现一种特定的服务或者功能,而且该程序有多种实现方式时使用。

          

                                    (策略模式静态图)

         策略模式中有三个对象:
      (1)       环境对象:该类中实现了对抽象策略中定义的接口或者抽象类的引用。
      (2)       抽象策略对象:它可由接口或抽象类来实现。
      (3)       具体策略对象:它封装了实现同不功能的不同算法。
      利用策略模式构建应用程序,可以根据用户配置等内容,选择不同有算法来实现应用程序的功能。具体的选择有环境对象来完成。采用这种方式可以避免由于使用条件语句而带来的代码混乱,提高应用程序的灵活性与条理性。

    5. /* 
    6. 这是一个表现僧人和道士的程序,僧人光头,使用棍子做武器,道士长小胡子,使用拂尘作武器 
    7. */ 
    8. public interface DisplayInte {
    9.     public void display();
    10. }
    11. public interface WeaponInte {
    12.     public void wuqi();
    13. }
    14. public class daoshiDisplayImpl implements DisplayInte {
    15.     public void display() {
    16.         // TODO Auto-generated method stub
    17.         System.out.println("道士是有头发的!!!");
    18.     }
    19. }
    20. public class heshangDisplayImpl implements DisplayInte {
    21.     public void display() {
    22.         // TODO Auto-generated method stub
    23.         System.out.println("和尚没有头发的");
    24.     }
    25. }
    26. public class daoshiWeaponImpl implements WeaponInte {
    27.     public void wuqi() {
    28.         // TODO Auto-generated method stub
    29.             System.out.println("道士使用的武器是拂尘!!!");
    30.     }
    31. }
    32. public class heshangWeaponImpl implements WeaponInte {
    33.     public void wuqi() {
    34.         // TODO Auto-generated method stub
    35.         System.out.println("和尚拿的武器是法仗!!!");
    36.     }
    37. }
    38. public class Daoshi extends Role {
    39.     public Daoshi() {
    40.         this.display=new daoshiDisplayImpl();
    41.         this.weapon=new daoshiWeaponImpl();
    42.         // TODO Auto-generated constructor stub
    43.     }
    44. }
    45. public class Heshang extends Role {
    46.     public Heshang() {
    47.         this.display=new heshangDisplayImpl();
    48.         this.weapon=new heshangWeaponImpl();
    49.         // TODO Auto-generated constructor stub
    50.     }
    51. }
    52. public class Role {
    53.     public String name;
    54.     public int age;
    55.     public DisplayInte display;
    56.     public WeaponInte weapon;
    57.     public void display()
    58.     {       
    59.         display.display();
    60.     }
    61.     public void weapon()
    62.     {
    63.         weapon.wuqi();
    64.     }
    65.     public void changeWeapon()
    66.     {
    67.         if(this instanceof Daoshi)
    68.         {
    69.             weapon=new heshangWeaponImpl();
    70.         }
    71.         else
    72.         {
    73.             weapon=new daoshiWeaponImpl();
    74.         }
    75.     }
    76.     
    77.     
    78. }
    79. public class Test {
    80.     /**
    81.      * @param args
    82.      */
    83.     public static void main(String[] args) {
    84.         // TODO Auto-generated method stub
    85.         Role oDaoshi=new Daoshi();
    86.         Role oHeshang=new Heshang();
    87.         oDaoshi.display();
    88.         oDaoshi.weapon();
    89.         oHeshang.display();
    90.         oHeshang.weapon();
    91.         oDaoshi.changeWeapon();
    92.         oDaoshi.display();
    93.         oHeshang.changeWeapon();
    94.         oHeshang.display();
    95.     }
    96. }

    发表于 @ 2008年08月06日 20:55:00|评论(loading...)|编辑|收藏

    新一篇: 客户端存储数据工具库-PersistJS | 旧一篇: Logger的简单使用

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © cyhgohappy