JavaÉè¼Æģʽ֮State(״̬ģʽ)
¶¨Ò壺
GOF¡¶Éè¼Æģʽ¡·Öиø״̬ģʽϵĶ¨ÒåΪ£ºÔÊÐíÒ»¸ö¶ÔÏóÔÚÆäÄÚ²¿×´Ì¬¸Ä±äʱ¸Ä±äËüµÄÐÐΪ¡£
ÏÈ¿´Ò»¸öÀý×Ó£º
package com.state;
public class KissingPrincess {
// ±ê־룬±êÖ¾ÊÇÇàÍÜ»¹ÊÇÍõ×Ó¡£
private boolean isFrog = true;
// ¸ù¾ÝisFrog½øÐв»Í¬µÄ²Ù×÷¡£
public void greet() {
if (isFrog)
System.out.println("frog!");
else
System.out.println("prince!");
}
// ½«isFrogÉèÖóÉfalse¡£
public void kiss() {
isFrog = false;
}
// Ö÷º¯Êý¡£
public static void main(String[] args) {
KissingPrincess prince = new KissingPrincess();
prince.greet();
prince.kiss();
prince.greet();
}
}
Êä³ö½á¹û£º
frog!
prince!
Õâ¸öÀý×ÓÖУ¬ÓÃÁËÒ»¸ö±äÁ¿isFrogÀ´±êʶÊÇÇàÍÜ»¹ÊÇÍõ×Ó£¬Èç¹ûÊÇÍõ×ӵĻ°£¬Êä³ö"prince!"£¬ÊÇÇàÍܵĻ°£¬Êä³ö:“frog!”¡£
±¾ÀýÖеÄд·¨£¬ÓøöÅóÓѵĻ°À´Ëµ£¬Ö»ÊÇ“ÈëÃż¶³ÌÐòÔ±µÄд·¨”¡£ÔÚjavaÖУ¬ÒªÊ±Ê±×¢ÒâOOP(Object Oriented Programming)µÄ¸ÅÄî¡£
Èç¹û״̬ºÜ¶àµÄ»°£¬¾Í»áʹÓúܶàif else Óï¾ä£¬²»½ö·±ËöÄÑÓÚά»¤£¬¶øÇÒûÓÐÌåÏÖ³öÃæÏò¶ÔÏó±à³ÌµÄ˼Ïë¡£
¶ÔÉÏÀýÓ¦ÓÃ״̬ģʽºó£¬¿ÉÒÔ±ä³ÉÈçϵĴúÂ룺
package com.state;
public class KissingPrincess2 {
private State state = new Frog();
private interface State {
void response();
}
private class Frog implements State {
@Override
public void response() {
System.out.println("frog!");
}
}
private class Prince implements State {
@Override
public void response() {
System.out.println("prince!");
}
}
public void greet() {
state.response();
}
public void change(State state) {
this.state = state;
}
public static void main(String[] args) {
KissingPrincess2 prince2 = new KissingPrincess2();
prince2.greet();
prince2.change(prince2.new Prince());
prince2.greet();
}
}
Êä³ö½á¹û:
frog!
prince!
ÉÏÊöÀý×Ó¾ÍÊÇstateģʽµÄ»ù±¾Ë¼Ï룬ϣÍû¶ÁÕßÅóÓÑÃÇÈÏÕæÌå»á¡£
ÕâÀïÔپٸöstateģʽµÄÀý×Ó£º
Íæ¹ýcsµÄÈ˶¼ÖªµÀ£¬csÀïÃæÓкܶàǹ£¬ak47°¡£¬m16°¡£¬µ«ÊDz»¹Üʲôǹ
Ïà¹ØÎĵµ£º
¼øÓÚÅÀ³æ¿ª·¢ÐèÒªÒ»¸öͼƬ½âÎö¹¦Äܵĺ¯Êý£¬µ½ÍøÂçÉϲéÕÒÁËһЩjni·½ÃæµÄÄÚÈÝ£¬²¢×öÁË×Ô¼ºµÄһЩÐ޸ģ¬¾ßÌåÈçÏ£º
Ä¿Ç°javaÓëdll½»»¥µÄ¼¼ÊõÖ÷ÒªÓÐ3ÖÖ£ºjni£¬jawinºÍjacob¡£Jni£¨Java Native Interface£©ÊÇsunÌṩµÄjavaÓëϵͳÖеÄÔÉú·½·¨½»»¥µÄ¼¼Êõ£¨ÔÚwindows\linuxϵͳÖУ¬ÊµÏÖjavaÓënative method»¥µ÷£©¡£ ......
¹¤×÷ÒѾÓаëÄêÁË£¬Í»È»Ïëдµã¶«Î÷£¬´óѧµÄʱºò¾ÍÓÐдÈռǵÄÏ°¹ß£¬µ«ÊÇ×Ô´ÓÈ¥Java06°àѧϰһֱµ½ÏÖÔÚ¹¤×÷£¬ÂýÂýµÄҲûÓÐʱ¼äȥдÈռǣ¬Ï£Íûͨ¹ýÕâƪÎÄÕÂÄÜÈÃJava˽ÛÓµÄѧµÜѧÃÃÃÇ¿´ÁËÓÐËù°ïÖú¡£
ÏàÐźܶàͬѧºÜÎÒÒ»Ñù´óËĵÄʱºò¶¼±È½ÏÃÔ㣬ÓÈÆäÊÇÎÒ¶ÁµÄ¼ÆËã»úרҵ£¬ËµÊµ»°´óѧÀïѧµÄºÍÉç»áʵ¼ÊÐèÒªµÄ» ......
²Î¿¼:
¡¡¡¡http://danadler.com/jacob/
¡¡¡¡http://jakarta.apache.org/poi/
¡¡¡¡http://www.onjava.com/pub/a/onjava/2003/01/22/poi.html
¡¡¡¡http://www.csdn.net/develop/article/15/15311.shtm
¡¡¡¡http://forum.java.sun.com/thread.jsp?forum=40&thread=382666&tstart=0&trange=15
¡¡¡¡Java Excel ......
s = new String("xyz");´´½¨Á˼¸¸öString Object?Á½¸ö¶ÔÏó¡£
String s="ÄãºÃ";int i=3; s=i+s; Õâ¸ö±í´ïʽ¶ÔÂð?ÔÚjavaÖлáÌáʾÊý¾ÝÀàÐͲ»Æ¥Åä¡£ÒòΪstringÊÇÀà!ÕýÈ·×ö·¨: s+="3" »òÕß s+='3'»òÕß s+=(char)i;
ÎÒÃÇÒªÒýÈëÁíÍâÒ»ÖÖ´´½¨String¶ÔÏóµÄ·½Ê½µÄÌÖÂÛ——ÒýºÅÄÚ°üº¬Îı¾¡£ÕâÖÖ·½Ê½ÊÇStringÌØÓеģ¬²¢ÇÒË ......
ÊÖÉÏÒ»¸öÏîÄ¿ÐèҪͨ¹ýusb¿ÚÈ¥¶ÁÈ¡usbkeyµÄÐÅÏ¢£¬³§¼ÒÌṩµÄÖ»ÓÐC/C++µÄ½Ó¿Ú£¬¶øÖ÷Ó¦ÓÃÊÇjavaµÄ£¬ËùÒÔÐèҪʹÓÃjavaÈ¥µ÷Óö¯Ì¬Á´½Ó¿â£¬ËùÒÔ»¨Á˵ãʱ¼äÑо¿ÁËÏÂJNI¼¼Êõ£¬jdk¶ÔJNI¼¼Êõ·â×°µÃºÜµ½Î»£¬Ê¹ÓÃÆðÀ´·Ç³£¼òµ¥£¬JNI¼¼Êõ×î¹Ø¼ü»¹ÊÇÔÚÓÚjniÊý¾ÝÀàÐͺͱ¾µØÊý¾ÝÀàÐ͵Äת»»¡£Ïȼòµ¥ÂÞÁÐÏÂJNIµ ......