Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

javaÉè¼Æģʽ_Compositeģʽ

Compositeģʽ(×éºÏ)
   JavaÉîÈëµ½Ò»¶¨³Ì¶È,¾Í²»¿É±ÜÃâµÄÅöµ½Éè¼ÆģʽÕâÒ»¸ÅÄî,Á˽âÉè¼Æģʽ,½«Ê¹×Ô¼º¶ÔjavaÖеĽӿڻò³éÏóÀàÓ¦ÓÃÓиüÉîµÄÀí½â.Éè¼ÆģʽÔÚjavaµÄÖÐÐÍϵͳÖÐÓ¦Óù㷺,×ñÑ­Ò»¶¨µÄ±à³Ìģʽ,²ÅÄÜʹ×Ô¼ºµÄ´úÂë±ãÓÚÀí½â,Ò×ÓÚ½»Á÷,Composite(×éºÏģʽ)ģʽÊDZȽϳ£ÓõÄÒ»¸öģʽ.
   Composite×éºÏģʽ£¬½«¶ÔÏóÒÔÊ÷Ðνṹ×éÖ¯ÆðÀ´,ÒÔ´ï³É“²¿·Ö£­ÕûÌå” µÄ²ã´Î½á¹¹£¬Ê¹µÃ¿Í»§¶Ë¶Ôµ¥¸ö¶ÔÏóºÍ×éºÏ¶ÔÏóµÄʹÓþßÓÐÒ»ÖÂÐÔ¡£
   Óŵã: 1.ʹ¿Í»§¶Ëµ÷Óüòµ¥£¬¿Í»§¶Ë¿ÉÒÔÒ»ÖµÄʹÓÃ×éºÏ½á¹¹»òÆäÖе¥¸ö¶ÔÏó£¬Óû§¾Í²»±Ø¹Øϵ×Ô¼º´¦ÀíµÄÊǵ¥¸ö¶ÔÏó»¹ÊÇÕû¸ö×éºÏ½á¹¹£¬Õâ¾Í¼ò»¯ÁË¿Í»§¶Ë´úÂë¡£
         2.¸üÈÝÒ×ÔÚ×éºÏÌåÄÚ¼ÓÈë¶ÔÏ󲿼þ. ¿Í»§¶Ë²»±ØÒòΪ¼ÓÈëÁËеĶÔÏ󲿼þ¶ø¸ü¸Ä´úÂë¡£
  ÔÚ´ËдÁË6¸öjavaÀàÀ´ÃèÊö˵Ã÷CompositeÉè¼ÆģʽµÄʵÏÖ·½Ê½£»
  1¡¢ Circle.java      ²¿¼þ-Ô²
  2¡¢ Graph.java       ²¿¼þ-³éÏóÀà
  3¡¢ Line.java        ²¿¼þ-Ïß
  4¡¢ Picture.java     ²¿¼þ-ͼ
  5¡¢ Rectangle.java   ²¿¼þ-·½
  6¡¢ PictureTest.java ´øÓÐmain·½·¨µÄ²âÊÔÀà
===============   1¡¢ Circle.java
package composite;
//²¿¼þ-Ô²
public class Circle extends Graph {
 public void draw() {
  System.out.println("Draw a circle.");
 }
}
===============   1 end
===============   2¡¢ Graph.java
package composite;
import java.util.Iterator;
//²¿¼þ-³éÏóÀà
public abstract class Graph{
 //»­Í¼
    public abstract void draw();
 //Ôö¼ÓÒ»¸öͼÐÎ
 public void add(Graph g){};
 //ɾ³ýÒ»¸öͼÐÎ×é¼þ
 public void remove(Graph g){};
 
 //»ñµÃ×éºÏÌåµÄÄÚ²¿²¿¼þ
 public Iterator<Graph> iter(){return null;};
}
===============   2 end
===============   3¡¢ Line.java
package composite;
//²¿¼þ-Ïß
public class Line extends Graph {
 public void draw() {
  System.out.p


Ïà¹ØÎĵµ£º

JavaỊ̈߳ºÏ̵߳ĵ÷¶È Èò½

JavaỊ̈߳ºÏ̵߳ĵ÷¶È-Èò½
 
Ï̵߳ÄÈò½º¬Òå¾ÍÊÇʹµ±Ç°ÔËÐÐ×ÅÏß³ÌÈóöCPU×ÊÔ´£¬µ«ÊÇÈ»¸øË­²»ÖªµÀ£¬½ö½öÊÇÈóö£¬Ïß³Ì״̬»Øµ½¿ÉÔËÐÐ״̬¡£
 
Ï̵߳ÄÈò½Ê¹ÓÃThread.yield()·½·¨£¬yield() Ϊ¾²Ì¬·½·¨£¬¹¦ÄÜÊÇÔÝÍ£µ±Ç°ÕýÔÚÖ´ÐеÄÏ̶߳ÔÏ󣬲¢Ö´ÐÐÆäËûÏ̡߳£
 
/**
* JavaỊ̈߳ºÏ̵߳ĵ÷¶È-Èò½
*
......

JavaỊ̈߳ºÏ̵߳Äͬ²½ ͬ²½¿é

JavaỊ̈߳ºÏ̵߳Äͬ²½-ͬ²½¿é
 
¶ÔÓÚͬ²½£¬³ýÁËͬ²½·½·¨Í⣬»¹¿ÉÒÔʹÓÃͬ²½´úÂë¿é£¬ÓÐʱºòͬ²½´úÂë¿é»á´øÀ´±Èͬ²½·½·¨¸üºÃµÄЧ¹û¡£
 
×·Æäͬ²½µÄ¸ù±¾µÄÄ¿µÄ£¬ÊÇ¿ØÖƾºÕù×ÊÔ´µÄÕýÈ·µÄ·ÃÎÊ£¬Òò´ËÖ»ÒªÔÚ·ÃÎʾºÕù×ÊÔ´µÄʱºò±£Ö¤Í¬Ò»Ê±¿ÌÖ»ÄÜÒ»¸öÏ̷߳ÃÎʼ´¿É£¬Òò´ËJavaÒýÈëÁËͬ²½´úÂë¿ìµÄ²ßÂÔ£¬ÒÔÌá¸ßÐÔÄÜ¡£
&nb ......

JavaỊ̈߳ºÐÂÌØÕ÷ Ëø£¨ÉÏ£©

JavaỊ̈߳ºÐÂÌØÕ÷-Ëø£¨ÉÏ£©
 
ÔÚJava5ÖУ¬×¨ÃÅÌṩÁËËø¶ÔÏó£¬ÀûÓÃËø¿ÉÒÔ·½±ãµÄʵÏÖ×ÊÔ´µÄ·âËø£¬ÓÃÀ´¿ØÖƶԾºÕù×ÊÔ´²¢·¢·ÃÎʵĿØÖÆ£¬ÕâЩÄÚÈÝÖ÷Òª¼¯ÖÐÔÚjava.util.concurrent.locks °üÏÂÃ棬ÀïÃæÓÐÈý¸öÖØÒªµÄ½Ó¿ÚCondition¡¢Lock¡¢ReadWriteLock¡£
 
Condition
Condition ½« Object ¼àÊÓÆ÷·½·¨£¨wait¡¢notify ......

JavaỊ̈߳ºÐÂÌØÕ÷ ×èÈû¶ÓÁÐ

JavaỊ̈߳ºÐÂÌØÕ÷-×èÈû¶ÓÁÐ
 
×èÈû¶ÓÁÐÊÇJava5Ïß³ÌÐÂÌØÕ÷ÖеÄÄÚÈÝ£¬Java¶¨ÒåÁË×èÈû¶ÓÁеĽӿÚjava.util.concurrent.BlockingQueue£¬×èÈû¶ÓÁеĸÅÄîÊÇ£¬Ò»¸öÖ¸¶¨³¤¶ÈµÄ¶ÓÁУ¬Èç¹û¶ÓÁÐÂúÁË£¬Ìí¼ÓÐÂÔªËصIJÙ×÷»á±»×èÈûµÈ´ý£¬Ö±µ½ÓпÕλΪֹ¡£Í¬Ñù£¬µ±¶ÓÁÐΪ¿Õʱºò£¬ÇëÇó¶ÓÁÐÔªËصIJÙ×÷ͬÑù»á×èÈûµÈ´ý£¬Ö±µ½ÓпÉÓÃÔªËØΪ ......

JavaỊ̈߳ºÐÂÌØÕ÷ Ô­×ÓÁ¿

JavaỊ̈߳ºÐÂÌØÕ÷-Ô­×ÓÁ¿
 
ËùνµÄÔ­×ÓÁ¿¼´²Ù×÷±äÁ¿µÄ²Ù×÷ÊÇ“Ô­×ӵĔ£¬¸Ã²Ù×÷²»¿ÉÔÙ·Ö£¬Òò´ËÊÇḬ̈߳²È«µÄ¡£
 
ΪºÎҪʹÓÃÔ­×Ó±äÁ¿ÄØ£¬Ô­ÒòÊǶà¸öÏ̶߳Ե¥¸ö±äÁ¿²Ù×÷Ò²»áÒýÆðһЩÎÊÌâ¡£ÔÚJava5֮ǰ£¬¿ÉÒÔͨ¹ývolatile¡¢synchronized¹Ø¼ü×ÖÀ´½â¾ö²¢·¢·ÃÎʵݲȫÎÊÌ⣬µ«ÕâÑùÌ«Âé·³¡£
Java5Ö®ºó£¬× ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ