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

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»¹Üʲôǹ


Ïà¹ØÎĵµ£º

Java Éè¼Æģʽ(12)

Observer
Intent
Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
How to
Subject
  
knows its observers. Any number of Observer objects may observe a subject.
  
provides an in ......

һλ»ÝÆÕjavaÑз¢¹¤³Ìʦ²ûÊöjavaÅàѵµÄ¸ÐÑÔ

¹¤×÷ÒѾ­ÓаëÄêÁË£¬Í»È»Ïëдµã¶«Î÷£¬´óѧµÄʱºò¾ÍÓÐдÈռǵÄÏ°¹ß£¬µ«ÊÇ×Ô´ÓÈ¥Java06°àѧϰһֱµ½ÏÖÔÚ¹¤×÷£¬ÂýÂýµÄҲûÓÐʱ¼äȥдÈռǣ¬Ï£Íûͨ¹ýÕâƪÎÄÕÂÄÜÈÃJava˽ÛÓµÄѧµÜѧÃÃÃÇ¿´ÁËÓÐËù°ïÖú¡£
    ÏàÐźܶàͬѧºÜÎÒÒ»Ñù´óËĵÄʱºò¶¼±È½ÏÃÔ㣬ÓÈÆäÊÇÎÒ¶ÁµÄ¼ÆËã»úרҵ£¬ËµÊµ»°´óѧÀïѧµÄºÍÉç»áʵ¼ÊÐèÒªµÄ» ......

java±¨±íJXLºÍPOI´òÓ¡ÉèÖÃ


JXLµÄ´òÓ¡ÉèÖÃÔÚjxl.SheetSettingsÕâ¸öÀàÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ý·½·¨Sheet£¨»òÕßWritableSheet£©#getSettings()»ñÈ¡¡£
1.Ò³Ãæ
1.1·½Ïò
SheetSetting#setOrientation(PageOrientation po)£»
²ÎÊý£º  PageOrientation#LANDSCAPE       ºáÏò´òÓ¡
PageOrientation# PO ......

javaÖÐÒì³£·ÖÀà


1. Òì³£»úÖÆ
      Òì³£»úÖÆÊÇÖ¸µ±³ÌÐò³öÏÖ´íÎóºó£¬³ÌÐòÈçºÎ´¦Àí¡£¾ßÌåÀ´Ëµ£¬Òì³£»úÖÆÌṩÁ˳ÌÐòÍ˳öµÄ°²È«Í¨µÀ¡£µ±³öÏÖ´íÎóºó£¬³ÌÐòÖ´ÐеÄÁ÷³Ì·¢Éú¸Ä±ä£¬³ÌÐòµÄ¿ØÖÆȨתÒƵ½Òì³£´¦ÀíÆ÷¡£
      ´«Í³µÄ´¦ÀíÒì³£µÄ°ì·¨ÊÇ£¬º¯Êý·µ»ØÒ»¸öÌØÊâµÄ½á¹ûÀ´±íʾ³öÏÖÒì³££¨Í ......

java native interface(JNI)¼¼Êõ¼òµ¥Ó¦ÓÃ

      ÊÖÉÏÒ»¸öÏîÄ¿ÐèҪͨ¹ýusb¿ÚÈ¥¶ÁÈ¡usbkeyµÄÐÅÏ¢£¬³§¼ÒÌṩµÄÖ»ÓÐC/C++µÄ½Ó¿Ú£¬¶øÖ÷Ó¦ÓÃÊÇjavaµÄ£¬ËùÒÔÐèҪʹÓÃjavaÈ¥µ÷Óö¯Ì¬Á´½Ó¿â£¬ËùÒÔ»¨Á˵ãʱ¼äÑо¿ÁËÏÂJNI¼¼Êõ£¬jdk¶ÔJNI¼¼Êõ·â×°µÃºÜµ½Î»£¬Ê¹ÓÃÆðÀ´·Ç³£¼òµ¥£¬JNI¼¼Êõ×î¹Ø¼ü»¹ÊÇÔÚÓÚjniÊý¾ÝÀàÐͺͱ¾µØÊý¾ÝÀàÐ͵Äת»»¡£Ïȼòµ¥ÂÞÁÐÏÂJNIµ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ