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

java flyweightģʽ

Flyweight ¶¨Òå:
±ÜÃâ´óÁ¿ÓµÓÐÏàͬÄÚÈݵÄСÀàµÄ¿ªÏú(ÈçºÄ·ÑÄÚ´æ),ʹ´ó¼Ò¹²ÏíÒ»¸öÀà(ÔªÀà).
ÃæÏò¶ÔÏóÓïÑÔµÄÔ­Ôò¾ÍÊÇÒ»Çж¼ÊǶÔÏó,µ«ÊÇÈç¹ûÕæÕýʹÓÃÆðÀ´,ÓÐʱ¶ÔÏóÊý¿ÉÄÜÏԵúÜÅÓ
´ó,±ÈÈç,×Ö´¦ÀíÈí¼þ,Èç¹ûÒÔÿ¸öÎÄ×Ö¶¼×÷Ϊһ¸ö¶ÔÏó,¼¸Ç§¸ö×Ö,¶ÔÏóÊý¾ÍÊǼ¸Ç§,ÎÞÒɺÄ
·ÑÄÚ´æ,ÄÇôÎÒÃÇ»¹ÊÇÒª"Çóͬ´æÒì",ÕÒ³öÕâЩ¶ÔÏóȺµÄ¹²Í¬µã,Éè¼ÆÒ»¸öÔªÀà,·â×°¿ÉÒÔ±»
¹²ÏíµÄÀà,ÁíÍâ,»¹ÓÐһЩÌØÐÔÊÇÈ¡¾öÓÚÓ¦ÓÃ(context),ÊDz»¿É¹²ÏíµÄ,ÕâÒ² Flyweight ÖÐÁ½
¸öÖØÒª¸ÅÄîÄÚ²¿×´Ì¬ intrinsic ºÍÍⲿ״̬ extrinsic Ö®·Ö.
Õâ¸öÊǶÔÕâ¸öģʽµÄ¶¨Ò壬ÎÒ¾õµÃ×îÖØÒªµÄÊÇÄܹ»¶ÔÒª´¦Àí¶ÔÏó½øÐÐÄÚ²¿×´Ì¬ºÍÍⲿ״̬µÄÇø·Ö£¬ÕâÑù¶ÔÏóµÄÄÚ²¿×´Ì¬¾ÍÄܹ²Ïí£¬µ«ÊǺܶàÀý×Ó¶¼°Ñflyweightģʽд³ÉÒ»pool£¬È»ºó¶ÔpoolÀïµÄ¶ÔÏó½øÐй²Ïí£¬ÕâÑùòËÆÆ«ÀëÁËflyweightģʽµÄ³õÖÔ¶øÇÒЧ¹û²»ÀíÏë¡£ÏÂÃæÊÇÍøÉÏÕÒµ½µÄÀý×Ó£¬±È½Ï·ûºÏģʽµÄÒâͼ
1.¶¨Òå³éÏó½Ó¿Ú
public interface Font {
public void SetFont(String color, int size);
public void GetFont();
}
2.½Ó¿ÚµÄ¾ßÌåʵÏÖ
public class ConcreteFont implements Font {
private String color;
private int size;
private String str;
public ConcreteFont(String s) {
str = s;
// id = "The char is: " + s;
}
public void SetFont(String _color, int _size) {
color = _color;
size = _size;
}
public void GetFont() {
System.out.println("String :" + str + "--- color is:" + color
+ "--- size is:" + size);
}
}
3.Flyweight factory ¸ºÔðά»¤Ò»¸ö Flyweight ³Ø(´æ·ÅÄÚ²¿×´Ì¬)
public class FontFactory {
private Hashtable<String, Font> charHashTable = new Hashtable();
public FontFactory() {
}
public Font GetFlyWeight(String s) {
if (charHashTable.get(s) != null) {
return (Font) charHashTable.get(s);
} else {
Font tmp = new ConcreteFont(s);
charHashTable.put(s, tmp);
return tmp;
}
}
public Hashtable GetFactory() {
return charHashTable;
}
}
²âÊÔ£º
public class Main {
public static void main(String[] args) {
int[] size = { 8, 9, 10, 11, 12 };
String[] color = { "FFFFFF", "000000", "FF00FF", "CCCCCC", "111111" };
FontFactory myFontFactory = new FontFactory(


Ïà¹ØÎĵµ£º

java serialVersionUID º¬Òå

serialVersionUID ÓÃÀ´±íÃ÷ÀàµÄ²»Í¬°æ±¾¼äµÄ¼æÈÝÐÔ
¡¡¡¡¼òµ¥À´Ëµ£¬JavaµÄÐòÁл¯»úÖÆÊÇͨ¹ýÔÚÔËÐÐʱÅжÏÀàµÄserialVersionUIDÀ´ÑéÖ¤°æ±¾Ò»ÖÂÐԵġ£ÔÚ½øÐз´ÐòÁл¯Ê±£¬JVM»á°Ñ´«À´µÄ×Ö½ÚÁ÷ÖеÄserialVersionUIDÓë±¾µØÏàӦʵÌ壨ÀࣩµÄserialVersionUID½øÐбȽϣ¬Èç¹ûÏàͬ¾ÍÈÏΪÊÇÒ»Öµģ¬¿ÉÒÔ½øÐз´ÐòÁл¯£¬·ñÔò¾Í»á³öÏÖÐòÁÐ ......

java web±ê¼Ç¼¼Êõ

1 jsp »ù´¡¸ÅÄî
    jspÊÇÔÚ´«Í³µÄhtmlÒ³ÃæÖУ¬¼ÓÈëjavaµÄ³ÌÐòƬ¶ÎºÍjsp±ê¼Ç£¬¾Í¹¹³ÉÁËjspÒ³Ãæ¡£µ±web·þÎñÆ÷Óöµ½¶ÔjspµÄ·ÃÎÊÇëÇóʱ£¬ÏÈÖ´ÐжÔÆäÖеÄjava³ÌÐòƬ¶Î£¬È»ºóÒÔhtmlµÄ¸ñʽ·µ»Ø¸øÓû§¡£   java³ÌÐòƬ¶Î¿ÉÒÔÓÃÀ´²Ù×÷Êý¾Ý¿â£¬Öض¨ÏòÍøÒ³£¬»òÕßÊÇ·¢ËÍE-mail ,ÑéÖ¤µÇ½ÐÅÏ¢£¬ ÕâЩ²Ù×÷¶¼ÊÇÔÚ·þÎñÆ ......

Java Annotation

×÷Õß:cleverpig(×÷ÕßµÄBlog:http://blog.matrix.org.cn/page/cleverpig
)
Ô­ÎÄ:http://www.matrix.org.cn/resource/article/44/44055_Java+Annotation+Reflect.html
¹Ø¼ü×Ö:java,annotation,reflect
ÔĶÁÌáʾ£ºÎÄÖÐÌáµ½µÄ³ÌÐò³ÉÔ±»òÕß³ÌÐòÔªËØÊÇÒ»¸ö¸ÅÄָ×é³É³ÌÐò´úÂëµÄµ¥Ôª£ºÈçÀà¡¢·½·¨¡¢³ÉÔ±±äÁ¿¡£
Ò»¡¢Annotatio ......

javaÀàÖÐдsqlÓï¾ä£¬²éѯÌõ¼þ°üº¬»»ÐÐ

detachedCriteria.add(Restrictions.or(
       Restrictions.like("chengBanDanWeiIds", rForm.getChengBanDanWeiIds()+(char)13, MatchMode.START),
       Restrictions.or(
          &n ......

ÊìÁ·µÄJava³ÌÐòÔ±Ó¦¸ÃÕÆÎյļ¼Êõ

1¡¢Óï·¨£ºJava³ÌÐòÔ±±ØÐë±È½ÏÊìϤÓï·¨£¬ÔÚд´úÂëµÄʱºòIDEµÄ±à¼­Æ÷¶ÔijһÐб¨´íÓ¦¸ÃÄܹ»¸ù¾Ý±¨´íÐÅÏ¢ ÖªµÀÊÇʲôÑùµÄÓï·¨´íÎó²¢ÇÒÖªµÀÈκÎÐÞÕý¡£
2¡¢ÃüÁ±ØÐëÊìϤJDK´øµÄһЩ³£ÓÃÃüÁî¼°Æä³£ÓÃÑ¡ÏÃüÁîÖÁÉÙÐèÒªÊìϤ£ºappletviewer¡¢ HtmlConverter¡¢jar¡¢ java¡¢ javac¡¢javadoc¡¢javap¡¢javaw¡¢native2ascii¡¢serialv ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ