??xml version="1.0" encoding="utf-8" standalone="yes"?>a级影片在线观看,国产精品一区免费在线,国产欧美一区二区三区在线老狼http://www.aygfsteel.com/justinlei/category/2530.htmlzh-cnFri, 18 Dec 2009 23:33:54 GMTFri, 18 Dec 2009 23:33:54 GMT60Java设计模式之计C理模?/title><link>http://www.aygfsteel.com/justinlei/articles/19875.html</link><dc:creator>JustinLei</dc:creator><author>JustinLei</author><pubDate>Tue, 15 Nov 2005 06:25:00 GMT</pubDate><guid>http://www.aygfsteel.com/justinlei/articles/19875.html</guid><wfw:comment>http://www.aygfsteel.com/justinlei/comments/19875.html</wfw:comment><comments>http://www.aygfsteel.com/justinlei/articles/19875.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/justinlei/comments/commentRss/19875.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/justinlei/services/trackbacks/19875.html</trackback:ping><description><![CDATA[描述Q?br> <br>   计数代理模式在客户对象调用服务提供者对象上Ҏ的前后执行诸如日志(loggingQ和计数QcountingQ一pd附加 功能时很有用。计C理模式徏议把q些附加功能装在一个单独的对象Q这个对象就是指计数代理对象Q而不是把q些附加的功能实现放到服务提供者的内部。良 好的对象设计的一个特征就是对象要专注于提供特定的功能。换句话_理想的对象不应该做各U不相干的事情。把诸如日志QloggingQ和计数 QcountingQ等cM的功能封装ؓ一个单独的对象Q而让服务提供者对象仅提供它自q特定功能。也是_只允许服务提供者对象执行定义良好、特? 的Q务?br> <br>   计数代理被设计成可以被客戯问的与服务提供者具有相同接口的对象。客户对象不是直接访问服务提供者,而是调用计数代理对象上的ҎQ计C理执行必要的U录日志QloggingQ和计数QcountingQ功能后Q再把方法调用传递给服务提供着对象。如?<br> <br> <table align="center" border="0" width="90%"> <tbody><tr><td><div align="center"><img src="http://yesky.anhuinews.com/imagelist/05/11/2828o18m1i2q.bmp"><br>Figure1: Generic Class Association When the Counting Proxy Pattern Is Applied </div></td></tr></tbody> </table> <br> <br>   下面的例子说明了如何在应用程序中利用计数代理?br> <br>   例子Q?br> <br>   让我们设计一个Orderc,cdơ如?QOrderIF接口声明了getAllOrdersd数据库中所有订单的单方法?br> <br> <table align="center" border="0" width="90%"> <tbody><tr><td><div align="center"><img src="http://yesky.anhuinews.com/imagelist/05/11/q0hxcf0kyz9y.bmp"><br>Figure2: Order Class Hierarchy </div></td></tr></tbody> </table> <br> <table align="center" bgcolor="#e3e3e3" border="1" bordercolor="#cccccc" width="90%"> <tbody><tr><td>public <a class="bluekey" target="_blank">interface</a> OrderIF { <br>public Vector getAllOrders(); <br>} </td></tr></tbody> </table> <br>   作ؓgetAllOrdersҎ实现的一部分QOrdercd用了FileUtil工具cMorder.txt文g中读取订单项?br> <br> <table align="center" bgcolor="#e3e3e3" border="1" bordercolor="#cccccc" width="90%"> <tbody><tr><td>public class Order <a class="bluekey" target="_blank">implements</a> OrderIF { <br> public Vector getAllOrders() { <br>  FileUtil fileUtil = new FileUtil(); <br>  Vector v = fileUtil.fileToVector("orders.txt"); <br>  return v; <br> } <br>} </td></tr></tbody> </table> <br>   让我们假定在调用getAllOrders()Ӟ需要把取数据文件所p的时间和记录条数要记录的log日志文g中?br> <br>   q个附加的功能可以设计一个单独的OrderProxycL实现Q它与真实对象Order一样实现OrderIF接口。这样保证了OrderProxy对象提供l客户与真实对象Order一L接口。如?<br> <br> <table align="center" width="90%"> <tbody><tr><td><div align="center"><img src="http://yesky.anhuinews.com/imagelist/05/11/6l0166q4mc67.bmp"><br>Figure3: Order Class Hierarchy <a class="bluekey" target="_blank">with</a> the Counting Proxy </div></td></tr></tbody> </table> <br> <table align="center" bgcolor="#e3e3e3" border="1" bordercolor="#cccccc" width="90%"> <tbody><tr><td>public class OrderProxy implements OrderIF { <br> private <a class="bluekey" target="_blank">int</a> counter = 0; <br> public Vector getAllOrders() { <br>  Order order = new Order(); <br>  counter++; <br>  long t1 = System.currentTimeMillis (); <br>  Vector v = order.getAllOrders(); <br>  long t2 = System.currentTimeMillis(); <br>  long timeDiff = t2 ? t1; <br>  String <a class="bluekey" target="_blank">msg</a> = "Iteration=" + counter + "::Time=" + timeDiff + "ms"; <br>  //log the message <br>  FileUtil fileUtil = new FileUtil(); <br>  fileUtil.writeToFile("log.txt?msg, true, true); <br>  return v; <br> } <br>} </td></tr></tbody> </table> <br>    客户对象MainApp想调用真实对象Order一栯用OrderProxy对象上的getAllOrders()ҎQOrderProxy对象 传递这个调用给真实对象Order,计算d所有订单所p的时间ƈ使用FileUtil帮助cd其纪录的log日志文g中。在q个q程中, OrderProxy扮演者计C理的角色?br> <br> public class MainApp { <br>  public static void main(String[] args) { <br>   OrderIF order = new OrderProxy(); <br>   Vector v = order.getAllOrders(); <br>   v = order.getAllOrders(); <br>   v = order.getAllOrders(); <br>   v = order.getAllOrders(); <br>  } <br> }<img src ="http://www.aygfsteel.com/justinlei/aggbug/19875.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/justinlei/" target="_blank">JustinLei</a> 2005-11-15 14:25 <a href="http://www.aygfsteel.com/justinlei/articles/19875.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JAVA的类反射http://www.aygfsteel.com/justinlei/articles/19874.htmlJustinLeiJustinLeiTue, 15 Nov 2005 06:24:00 GMThttp://www.aygfsteel.com/justinlei/articles/19874.htmlhttp://www.aygfsteel.com/justinlei/comments/19874.htmlhttp://www.aygfsteel.com/justinlei/articles/19874.html#Feedback0http://www.aygfsteel.com/justinlei/comments/commentRss/19874.htmlhttp://www.aygfsteel.com/justinlei/services/trackbacks/19874.html/**
  * cd实现动态类调用
  * @param instance  一个信息获取类的实?br>  * @param methodName Ҏ名称
  * @param classes 参数cd数组
  * @param objects 参数数组
  * @return Object q回了方法执行后的结?br>  */
 private Object invokeInstanceMethod(
            final Object instance, final String methodName,
   final Class[] classes, final Object[] objects) {
        try {
            Method method;
            try {
                method = instance.getClass().getDeclaredMethod(methodName, classes);
            }
            catch (NoSuchMethodException e) {
                method = instance.getClass().getMethod(methodName, classes);
            }
            method.setAccessible(true);
            return method.invoke(instance, objects);
        }
        catch (NoSuchMethodException e) {
            throw new RuntimeException(e.getMessage());
        }
        catch (IllegalAccessException e) {
            throw new RuntimeException(e.getMessage());
        }
        catch (InvocationTargetException e) {
            throw new RuntimeException(e.getTargetException().getMessage());
        }
    }

 /* Q非 JavadocQ?br>  * @see com.eware.dataBaseOperation.dataOperateToolKit
  * .dataBaseOperate.InterFaceGetOwnerDataInfo#getOwnerTables()
  */
 /**
  * 实现了接口方法获取当前用h有表的信?br>  */
 public ResultSet getOwnerTables() {
  // TODO 自动生成Ҏ存根
  return (ResultSet)invokeInstanceMethod(goic, "getOwnerTables",
    new Class[]{}, new Object[]{});
 }



JustinLei 2005-11-15 14:24 发表评论
]]>
JAVA内部cȝ基本特征http://www.aygfsteel.com/justinlei/articles/19873.htmlJustinLeiJustinLeiTue, 15 Nov 2005 06:23:00 GMThttp://www.aygfsteel.com/justinlei/articles/19873.htmlhttp://www.aygfsteel.com/justinlei/comments/19873.htmlhttp://www.aygfsteel.com/justinlei/articles/19873.html#Feedback0http://www.aygfsteel.com/justinlei/comments/commentRss/19873.htmlhttp://www.aygfsteel.com/justinlei/services/trackbacks/19873.html内部cLJava语言一个重要的基本Ҏ,?/span>Java开发的许多领域都会l常用到。内部类的定义说单一点就是将一个类定义在另外一个类的内部。内部类允许你把一些逻辑相关的类l织在一P控制内部cM码的可视性,它和cȝl合是完全不同的概念。内部类主要有以下比较关键的Ҏ:

 

1.  普通的非内部类不能被声明ؓprivate?/span>protectedQ否则就失去了创cȝ意义。但是内部类通常可以被声明ؓprivate?/span>protectedcdQ因样可以防止他人对该内部类实现的功能进行修改,辑ֈ隐藏实现l节的目的。例如:

class Fruit {

  private class Weight {

private String i;

private Weight(String j) {

  i = j;

}

public String read() {

  return i;

}

}

}

class test {

  public static void main(String[] args) {

Fruit f = new Fruit();

f.Weight w = f.new Weight(); //不能讉Kprivatec,如果Weight?/span>protectedcd则可?/span>

}

}

2.  在方法或某控制语?/span>(if/for/while{?/span>)的作用域内定义内部类Q将只能在该范围内调用内部类的方法和成员变量?/span>

3.  匿名内部cL一U特D的内部c,如果希望它用一个在其外部定义的对象Q那么编译器会要求其参数引用?/span>final的?/span>

public class Fruit {

  public Tea cont(final int j) {

return new Tea() {

  private int i = j;

  public int read() {

    return i;

}

}; //注意q里的分?/span>

}

public static void main(String[] args) {

  Fruit f = new Fruit();

  Tea t = f.cont;

}

}

而当Ҏcont(final int j)中的参数j只是被传递到匿名cM的构造器Ӟ可以不用被声明ؓfinalcdQ如return new Tea(j)。这里提C匿名内部cȝ构造器Q那么它是怎么被初始化的呢Q?/span>

public class Fruit {

  public Tea cont(int j) {

return new Tea(j) {

System.out.println(j);

};

}

}

         q可以这样初始化匿名内部c:

public class Fruit {

  public Tea cont(final int j) {

return new Tea(j) {

  int i;

  // 初始化匿名内部类

  {

  i = j;

  System.out.print(i);

}

};

}

}

         Ҏcont()可以被称为实例初始化ҎQ得匿名内部类通过构造器而被初始化,在实际应用中Q我们不能重载实例初始化ҎQ因为匿名内部类只能有一个构造方法?/span>

JustinLei 2005-11-15 14:23 发表评论
]]>
JAVAz子类和?/title><link>http://www.aygfsteel.com/justinlei/articles/19872.html</link><dc:creator>JustinLei</dc:creator><author>JustinLei</author><pubDate>Tue, 15 Nov 2005 06:21:00 GMT</pubDate><guid>http://www.aygfsteel.com/justinlei/articles/19872.html</guid><wfw:comment>http://www.aygfsteel.com/justinlei/comments/19872.html</wfw:comment><comments>http://www.aygfsteel.com/justinlei/articles/19872.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/justinlei/comments/commentRss/19872.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/justinlei/services/trackbacks/19872.html</trackback:ping><description><![CDATA[JAVA中的cd存在于一个体pȝ构中.在JAVA中,一个类可以通过使用extends关键字声明ؓ另一个类的子c?subclass)。子cd 以从其超c(superclassQ承(inheritQ变量和ҎQƈ加以使用Q就如同q些变量和方法由该子cLw所声明的一P <p>class Animal {<br>    float weight;<br>    ...<br>    void eat() {<br> ...<br>    }<br>    ...<br>}</p> <p>class Mammal extends Animal {<br>    int heartRate;<br>    //l承weight<br>    ...<br>    void breathe() {<br> ...<br>    }<br>    //l承eat<br>}</p> <p>cd能扩展另外的一个类。只支持单承(single inheritanceQ?/p> <p>子类可以q一步派生子cR?/p> <img src ="http://www.aygfsteel.com/justinlei/aggbug/19872.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/justinlei/" target="_blank">JustinLei</a> 2005-11-15 14:21 <a href="http://www.aygfsteel.com/justinlei/articles/19872.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java设计模式之虚拟代理模?/title><link>http://www.aygfsteel.com/justinlei/articles/19871.html</link><dc:creator>JustinLei</dc:creator><author>JustinLei</author><pubDate>Tue, 15 Nov 2005 06:21:00 GMT</pubDate><guid>http://www.aygfsteel.com/justinlei/articles/19871.html</guid><wfw:comment>http://www.aygfsteel.com/justinlei/comments/19871.html</wfw:comment><comments>http://www.aygfsteel.com/justinlei/articles/19871.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/justinlei/comments/commentRss/19871.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/justinlei/services/trackbacks/19871.html</trackback:ping><description><![CDATA[<p>虚拟代理模式(Virtual Proxy)是一U节省内存的技术,它徏议创建那些占用大量内存或处理复杂的对象时Q把创徏q类对象推迟C用它的时候。在特定的应用中Q不同部分的功能 ׃同的对象l成Q应用启动的时候,不会立即使用所有的对象。在q种情况下,虚拟代理模式推迟对象的创建直到应用程序需要它为止。对象被应用W一ơ引 用时创徏q且同一个实例可以被重用。这U方法优~点q存?<br><br></p> <div id="wmqeeuq" class="guanggao"><span id="contentAdv"></span></div>   优点Q?br> <br>   q种Ҏ的优ҎQ在应用E序启动Ӟ׃不需要创建和装蝲所有的对象Q因此加速了应用E序的启动?br> <br>   ~点:<br> <br>   因ؓ不能保证特定的应用程序对象被创徏Q在讉Kq个对象的Q何地方,都需要检确认它不是I?null)。也是Q这U检的旉消耗是最大的~点?br> <br>    应用虚拟代理模式Q需要设计一个与真实对象h相同接口的单独对象(指虚拟代理)。不同的客户对象可以在创建和使用真实对象地方用相应的虚拟对象来代 ѝ虚拟对象把真实对象的引用作为它的实例变量维护。代理对象不要自动创建真实对象,当客户需要真实对象的服务Ӟ调用虚拟代理对象上的ҎQƈ且检真 实对象是否被创徏?br> <br>   如果真实对象已经创徏Q代理把调用转发l真实对象,如果真实对象没有被创建:<br> <br>   1Q?代理对象创徏真实对象<br> <br>   2Q?代理对象把这个对象分配给引用变量?br> <br>   3Q?代理把调用{发给真实对象<br> <br>    按照q种安排Q验证对象存在和转发Ҏ调用q些l节对于客户是不可见的。客户对象就像和真实对象一样与代理对象q行交互。因此客户从真实对象是否ؓ null中解脱出来,另外Q由于创Z理对象在旉和处理复杂度上要于创徏真实对象。因此,在应用程序启动的时候,用代理对象代替真实对象初始化?br> <br>   例子Q?br> <br>    假设我们建立一个JAVAE序的集成开发环境(Integrated Development EnvironmentQ?q个环境包括三个功能Q编译、运行、生成JavaDoc文。在新徏和编辑JavaE序Ӟ最为常用的是编译和q行。至于生? JavaDoc文对于每一个JavaE序不是必需的。因此,在Java开发环境启动时Q不要创建和装蝲实现集成开发环境全部功能的所有对象,仅创建那? 在编辑、编译、运行时用到的对象,保留提供生成JavaDoc文档的对象,q是一个好的设计思想。这U对象创建策略能够高效地利用内存I间q且加快了集? 开发环境的启动速度?br> <br>   假设~译、运行、生成JavaDoc文q些功能分别׃个工L提供??Compiler、Runtime和JavaDoc。客户对象可以访问的不同IDE操作的接口以抽象cIDEOperation的Ş式定义?br> <br> <table align="center" bgcolor="#e3e3e3" border="1" bordercolor="#cccccc" width="90%"> <tbody><tr><td>public abstract class IDEOperation { <br> private Compiler cmp; <br> private Runtime rtime; <br> public void compile(String javaFile) { <br>  cmp.compile(javaFile); <br> } <br> public void run(String classFile) { <br>  rtime.run (classFile); <br> } <br> //to be delayed until needed. <br> public abstract void generateDocs(String javaFile); <br> public IDEOperation() { <br>  cmp = <a class="bluekey" target="_blank">new</a> Compiler(); <br>  rtime = new Runtime(); <br> } <br>} </td></tr></tbody> </table> <br>    cIDEOperation提供了编译、运行javaE序Ҏ的实玎ͼ作ؓ它构造函数的一部分QIDEOperation创徏和装载了q行~译和执行操 作的Compiler和Runtime对象。生成JavaDoc文档的方法generateDocsҎ被设计成抽象的方法,由它的子cL实现?br> <br>   让我们定义抽象类IDEOperation的一个具体子cRealProcessor。作为RealProcessor构造函数的一部分Q创建JavaDoc对象来提供生成JavaDoc文的服务,通过使用JavaDoc对象功能实现generateDocsҎ?br> <br> <table align="center" bgcolor="#e3e3e3" border="1" bordercolor="#cccccc" width="90%"> <tbody><tr><td>public class RealProcessor extends IDEOperation { <br> JavaDoc jdoc; <br> public RealProcessor() { <br>  super(); <br>  jdoc = new JavaDoc(); <br> } <br> public void generateDocs(String javaFile) { <br>  jdoc.generateDocs(javaFile); <br> } <br>}</td></tr></tbody> </table> <br>    通过上面的实玎ͼRealProcessorcd含了~译、运行和生成JavaDoc文的所有功能。像我们原来讨论的,生成JavaDoc文的功? 不是每一个JavaE序所必须的,当RealProcessor实例化的时候,包括负责生成JavaDoc文的JavaDoc对象的一pd对象被创建? 推迟创徏JavaDoc对象有以下优点:<br> <br>   1Q?加速了RealProcessor对象的创建时_因ؓ它的构造函数创建的很少的对象?br> <br>   2Q?高效地利用内存,因ؓ在不需要对象服务的时候,不需要把对象保持在内存中?br> <br>    在不改变RealProcessor实现的前提下Q可以通过定义IDEOperation的另外一个子cProxyProcessor来实现虚拟代理? 因ؓRealProcessor和ProxyProcessor׃n相同的接口,客户对象可以用ProxyProcessor代替 RealProcessor。图25.1展示了类层次Q?br> <br> <table align="center" border="0" width="90%"> <tbody><tr><td><div align="center"><img src="http://dev.yesky.com/imagelist/05/11/rh04rjju4aj5.bmp"> <br><br>Figure 25.1: IDEOperation Class Hierarchy </div></td></tr></tbody> </table> <br> <table align="center" bgcolor="#e3e3e3" border="1" bordercolor="#cccccc" width="90%"> <tbody><tr><td>public class ProxyProcessor extends IDEOperation { <br> private RealProcessor realProcessor; <br> public void generateDocs(String javaFile) { <br>  /* <br>  In order to generate javadocs <br>  the proxy loads the actual object and <br>  invokes its methods. <br>  */ <br>  if (realProcessor == null) { <br>   realProcessor = new RealProcessor(); <br>  } <br>  realProcessor.generateDocs(javaFile); <br> } <br>} </td></tr></tbody> </table> <br>    作ؓ自己的实例变量,ProxyProcessorl护了RealProcessor对象的一个引用。作为generateDocsҎ的一部分Q? ProxyProcessor引用变量是否被初始化ؓRealProcessor对象。如果没有被初始化,它创Z个RealProcessor对象 q把q个对象分配l它的实例变量。一旦RealProcessor对象已经被创建,p用其上的generateDocsҎ?br> <br>   实际上,也就是当客户对象W一ơ请求生javadoc文ӞRealProcessor才被初始化装入内存中。反q来Q直到客户需要ؓJavaE序生成javadocsӞJavaDoc对象才会被创建和装入内存中?br> <br>   客户对象像调用真实处理对象一栯用ProxyProcessor上的ҎQƈ不需要关心(知道QRealProcessor对象是否存在?至于验证、检和ProxyProcessor和RealProcessor之间的交互、这Ll节对于客户对象是透明的?br> <br> <table align="center" bgcolor="#e3e3e3" border="1" bordercolor="#cccccc" width="90%"> <tbody><tr><td>public class Client { <br> public static void main(String[] args) { <br>  /* <br>  At this <a class="bluekey" target="_blank">point</a> <a class="bluekey" target="_blank">objects</a> required for <br>  the compile and run operations are <br>  created, but not the objects that provide the <br>  generate Javadoc functionality. <br>  */ <br>  IDEOperation IDE = new ProxyProcessor(); <br>  IDE.compile("test.java"); <br>  IDE.run("test.class"); <br>  /* <br>  The Javadoc functionality <a class="bluekey" target="_blank">is</a> accessed <br>  For the first time and hence the <br>  Object offering the Javadoc <a class="bluekey" target="_blank">generation</a> <br>  Functionality is loaded at this point. <br>  */ <br>  IDE.generateDocs("test.java"); <br> } <br>} </td></tr></tbody> </table> <img src ="http://www.aygfsteel.com/justinlei/aggbug/19871.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/justinlei/" target="_blank">JustinLei</a> 2005-11-15 14:21 <a href="http://www.aygfsteel.com/justinlei/articles/19871.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Eclipse家族法则(扩展?http://www.aygfsteel.com/justinlei/articles/19870.htmlJustinLeiJustinLeiTue, 15 Nov 2005 06:20:00 GMThttp://www.aygfsteel.com/justinlei/articles/19870.htmlhttp://www.aygfsteel.com/justinlei/comments/19870.htmlhttp://www.aygfsteel.com/justinlei/articles/19870.html#Feedback0http://www.aygfsteel.com/justinlei/comments/commentRss/19870.htmlhttp://www.aygfsteel.com/justinlei/services/trackbacks/19870.html扩展?/strong>

1. 贡献法则(Contributin Rule):一切皆是A?/font>

2.遵@法则(Conformance Rule):插g必须遵@预期的接?/font>

3.׃n法则(sharing Rule):增加,不要取代

4.有样学样法则(Monkey See/Monkey Do Rule):遇到问题?首先复制cM插g的结?/font>

5.相关性法?Relevance Rule):只有在操作有可能成功时才昄你所贡献的操?/font>

6.整合法则(Integration Rule):要整合不要分?/font>

7.责Q法则(Responsibility Rule):明确 指出你开发的插g旉题的源头

8.针对API契约~程法则(Program To API Contract Rule):首先查Eclipse API契约,然后后针对契U编E?/font>

9."其他"法则(Other Rule):让用户可以选择所有东?但把那些通常不用于当前视角的选项攑֜Other...对话框中

10.IResource适配法则(Adapt To IResource Rule):应该量为领域对象定义IResource适配?/font>

11.分层法则(Strata Rule):语a无关的功能与特定于具体语a的功能分开,核心功能与UI功能分开

12.使用q诏性法?User Continuity Rule):在多ơ回话期?应该保持用户界面状态一?/font>



JustinLei 2005-11-15 14:20 发表评论
]]>
传递和q回对象Q传递句?/title><link>http://www.aygfsteel.com/justinlei/articles/19868.html</link><dc:creator>JustinLei</dc:creator><author>JustinLei</author><pubDate>Tue, 15 Nov 2005 06:15:00 GMT</pubDate><guid>http://www.aygfsteel.com/justinlei/articles/19868.html</guid><wfw:comment>http://www.aygfsteel.com/justinlei/comments/19868.html</wfw:comment><comments>http://www.aygfsteel.com/justinlei/articles/19868.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/justinlei/comments/commentRss/19868.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/justinlei/services/trackbacks/19868.html</trackback:ping><description><![CDATA[<p>句柄传递进入一个方法时Q指向的仍然是相同的对象?/p> <p>public class PassHandles {<br>          static void f(PassHandles h) {<br>          System.out.println("h inside f(): " + h);<br>}<br>          public static void main(String[] args) {<br>                    PassHandles p = new PassHandles();<br>                    System.out.println("p inside main(): " + p);<br>          f(p);<br>         }<br>} </p> <p><br>toString Ҏ会在打印语句里自动调用,而PassHandles 直接从Object l承Q没有toString 的重新定义?br>因此Q这里会采用toString 的Object 版本Q打印出对象的类Q接着是那个对象所在的位置Q不是句柄,?br>是对象的实际存储位置Q。输出结果如下:<br>p inside main(): <a href="mailto:PassHandles@1653748">PassHandles@1653748</a><br>h inside f() : <a href="mailto:PassHandles@1653748">PassHandles@1653748</a><br>可以看到Q无论p q是h 引用的都是同一个对象。这比复制一个新的PassHandles 对象有效多了Q我们?br>一个参数发l一个方法。但q样做也带来了另一个重要的问题Q别名问?/p> <img src ="http://www.aygfsteel.com/justinlei/aggbug/19868.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/justinlei/" target="_blank">JustinLei</a> 2005-11-15 14:15 <a href="http://www.aygfsteel.com/justinlei/articles/19868.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Eclipse家族法则(促成?http://www.aygfsteel.com/justinlei/articles/19867.htmlJustinLeiJustinLeiTue, 15 Nov 2005 06:15:00 GMThttp://www.aygfsteel.com/justinlei/articles/19867.htmlhttp://www.aygfsteel.com/justinlei/comments/19867.htmlhttp://www.aygfsteel.com/justinlei/articles/19867.html#Feedback0http://www.aygfsteel.com/justinlei/comments/commentRss/19867.htmlhttp://www.aygfsteel.com/justinlei/services/trackbacks/19867.html促成?

1.邀h?Invitation Rule):可能的邀请别Zؓ你的作品做出贡献

2.懒加载法?Lazy Loading Rule):只有在真正需要的时候才加蝲插g

3.安全q_法则(Safe Platform Rule):作ؓ扩展点的提供?你必M护好自己,不要让扩展者的误操作给你造成损失

4.公^竞赛法则(Fair Play Rule):所有用者遵守同L游戏规则,包括我自?/p>

5.明确扩展法则(Explicit Extension Rule):明确说明q_的什么地方可供扩?/p>

6.发散性法?Diversity Rule):一个扩展点接纳多个扩展

7.良好防M法则(Good Fences Rule):如果要交出程序的控制?首先保护好你自己

8.用户军_法则(User Arbitration Rule):如果有多个选择,q户决定用哪?/p>

9.明确API法则(Explicit API Rule):API与插件内部用的cd开

10.E_性法?Stability Rule):如果你已l开始邀请其他h作出贡献,׃要再改变规则

11.保守API法则(Defensive API Rule):只暴露你有信心的API,但同时也要做好准备暴露更多的API,因ؓ使用者会邀请你q样?/p>

JustinLei 2005-11-15 14:15 发表评论
]]>
ThreadcdRunnable接口http://www.aygfsteel.com/justinlei/articles/19866.htmlJustinLeiJustinLeiTue, 15 Nov 2005 06:14:00 GMThttp://www.aygfsteel.com/justinlei/articles/19866.htmlhttp://www.aygfsteel.com/justinlei/comments/19866.htmlhttp://www.aygfsteel.com/justinlei/articles/19866.html#Feedback0http://www.aygfsteel.com/justinlei/comments/commentRss/19866.htmlhttp://www.aygfsteel.com/justinlei/services/trackbacks/19866.html 解释器中一个实际的U程Qƈ作ؓ控制和协调其执行的一个句柄。利用Thread对象Q可以启动线E?br> {待其完成、要求它睡眠一D|_或者时中断其活动。Threadcȝ构造函数可接受U程应当在哪?br> 开始执行等{有关的信息。从概念上说Q我们只希望告诉它所要运行的ҎQ但是由于Java中不存在
Ҏ指针Q至没有这U意义的Ҏ指针Q,因此我们q不能直接指定方法。与此不同,必须采取一U?br> q回U\Q即使用java.lang.Runnable接口来创Z个对象,此对象中包含一个“可q行”的斏V?br> Runnable接口只定义了唯一的一个通用Ҏ?br>  public interface Runnable {
 abstract public void run();
}
 每个U程的生命周期都始于执行Runnable对象中的run()Ҏ。此对象是传递给U程构造函
数的“目标对象”。run()Ҏ可以包含M代码、但它必L公共的,不仅没有M实参Q而且也没
有返回|另外不会抛出M受查异常?br>  M包含有合适的run()Ҏ的类都可以声明它实现了Runnable接口。此cȝ实例是一?br> 可运行的对象Q它可以作ؓ一个线E的目标。如果不希望run()直接攑֜对象中(而且通常不会q样
做)Q则可以建立一个适配器类Q由它作Z个RunnablecR适配器的run()Ҏ则能够在U程启动

后调用Q何需要的Ҏ



JustinLei 2005-11-15 14:14 发表评论
]]>
ANThttp://www.aygfsteel.com/justinlei/articles/19865.htmlJustinLeiJustinLeiTue, 15 Nov 2005 06:12:00 GMThttp://www.aygfsteel.com/justinlei/articles/19865.htmlhttp://www.aygfsteel.com/justinlei/comments/19865.htmlhttp://www.aygfsteel.com/justinlei/articles/19865.html#Feedback0http://www.aygfsteel.com/justinlei/comments/commentRss/19865.htmlhttp://www.aygfsteel.com/justinlei/services/trackbacks/19865.html
<?xml version="1.0"?>
<!-- build.xml - a simple Ant buildfile -->
<project name="Simple Buildfile" default="compile" basedir=".">
<!-- The directory containing source code -->
<property name="src.dir" value="src"/>
<!-- Temporary build directories -->
<property name="build.dir" value="build"/>
<property name="build.classes" value="${build.dir}/classes"/>
<property name="build.lib" value="${build.dir}/lib"/>
<!-- Target to create the build directories prior to the -->
<!-- compile target. -->
<target name="prepare">
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes}"/>
<mkdir dir="${build.lib}"/>
</target>
<target name="clean" description="Removes all generated files.">
<delete dir="${build.dir}"/>
</target>
<target name="compile" depends="prepare"
description="Compiles all source code.">
<javac srcdir="${src.dir}" destdir="${build.classes}"/>
</target>
<target name="jar" depends="compile"
description="Generates test.jar in the 'dist' directory.">
<!-- Exclude unit tests from the final JAR file -->
<jar jarfile="${build.lib}/oreilly.jar"
basedir="${build.classes}"
excludes="**/*Test.class"/>
</target>
<target name="all" depends="clean,jar"
description="Cleans, compiles, then builds the JAR file."/>
</project>

JustinLei 2005-11-15 14:12 发表评论
]]>
վ֩ģ壺 ̩| ɽ| | ½| | | | | ײ| ӽ| | | | Դ| ֦| | | ̫| ɽ| | | ָ| | ٹ| ÷ӿ| | | Ǧɽ| | | | | | Դ| | | | | | | |