javaÉè¼Æģʽ£º×°ÊÎÆ÷ģʽ[Decorator]
×°ÊÎÆ÷ģʽÖ÷ÒªÓ¦ÓÃÓÚÕâÑùÒ»ÖÖ³¡ºÏ£¬µ±ÄãÒѾÓÐÁËÒ»¸öÄ¿±êÀ࣬²¢ÇÒËüÊÇÒ»¸ö½Ó¿ÚµÄʵÏÖÀ࣬ÔÚ¶Ô¸ÃÀàʹÓõĺóÆÚ·¢ÏÖÐèÒª¶ÔÏàÓ¦½Ó¿Ú³ÌÐòµÄÇ°ºó×ö¸ü¶àµÄ´¦Àí£¬ÕâЩ´¦ÀíÊDZ仯µÄ£¬²»¹Ì¶¨µÄ£¬µ«ÊÇÓв»ÄÜÈ¥ÐÞ¸ÄÕâ¸öÄ¿±êÀ࣬ÕâʱÎÒÃǾͿÉÒÔʹÓÃÕâ¸ö×°ÊÎÆ÷ģʽ£º
±ÈÈ磬ÎÒÃÇÒѾÓÐÒ»¸ö¸¶¿îµÄ·½·¨ payMoney(long count) £¬Õâ¸ö·½·¨Ö»¸ºÔð½«Ç®¸¶¸ø¶Ô·½£¬²»×öÆäËû²Ù×÷£¬µ«ÊÇÕâʱÎÒÃÇÐèÒª¼Ç¼ÏÂÕâ¸ö¸¶¿îµÄ²Ù×÷£¬²¢°ÑÕâ¸ö²Ù×÷¼Ç¼µ½ÈÕÖ¾ÎļþÖÐÒÔ·½±ãÈÕºóµÄ²é¿´£¬±ÈÈçÕâ¸ö·½·¨½Ð×ö insertLog(String str) £¬ÓÐÒ»ÖÖ°ì·¨¾ÍÊÇʹÓü̳У¬²¢¸´Ð´ÏàÓ¦µÄ payMoney(long count) ·½·¨£¬ÕâÑùÒ²¿ÉÒÔÂú×ãÌõ¼þ£¬µ«ÊÇÎÊÌâ³öÀ´ÁË£¬Èç¹ûÎÒÃÇÓÖÓÐÆäËûµÄ²Ù×÷£¬ÀýÈç֪ͨ¸¶¿îÈËÒѾ½«¿î¶î¸¶³ö notic(String username) £¬ÕâʱºòÕâô°ì£¬µ±È»ÎÒÃÇÈÔÈ»¿ÉÒÔͨ¹ý¼Ì³ÐÀ´ÊµÏÖ£¬¿ÉÊÇÈç¹ûÎÒÏÖÔÚÓв»Ï뽫¸¶¿î²Ù×÷¼Ç¼µ½ÈÕÖ¾ÎļþÖÐÁË£¬ÄÇÎÒÓÖ¸ÃÕâô°ì£¿
ΪÁ˽â¾öÕâÖÖÎÊÌ⣬ÎÒÃÇʹÓÃÁË ×°ÊÎÆ÷ģʽ £¬ÔÚÎÒÃǵÄÓ¦ÓÃÖпÉÒÔʹÓò»Í¬µÄ×°ÊÎÆ÷ÀࣨÒÔ¼°×°ÊÎÆ÷ÀàµÄ×éºÏ£©À´´ïµ½ÒÔÉϵÄÄ¿µÄ¡£
ÔÙ½«ÎÊÌâ¼ò»¯£¬ÎÒÃÇÒªÔÚ¿ØÖÆ̨Êä³ö×Ö·û£¬µ«ÊÇÐèÒªÔÚ×Ö·ûÇ°ºó¼ÓÉÏ“*”ºÍ“+”£¬Ò²¾ÍÊÇ˵£¬ÎÒ¿ÉÄÜÐèÒªÔÚÎÒÊäÈëµÄ×Ö·ûÇ°ºó¼ÓÉÏ“*”£¬Ò²¿ÉÄܹýÁË»á¶ùÓÖÏë¼Ó“+”¶ø²»ÊÇ“*”£¬»òÕßÓÖÏë“*”ºÍ“+”¶¼¼ÓÉÏ£¬ÓлòÕ߶¼²»Ïë¼Ó¡£
×°ÊÎÆ÷ģʽ ÈÃÕâЩҪÇó¶¯Ì¬µÄÅäÖóöÀ´£¬Ò²¾ÍÊÇ˵ÔÚÔËÐÐʱ²»ÐèÒª¸Ä±äÔÀ´ÒѾÉú³ÉºÃµÄ¶ÔÏó¡£
ÈÃÎÒÃÇÀ´¿´¿´Õâ¸ö½â¾ö·½°¸µÄ ×°ÊÎÆ÷ģʽ µÄÀàͼ°É£º
ÆäÖУ¬MyText ÀàΪÎÒÃÇÒªÏÔʾµÄ×Ö·ûÀ࣬¶ø DecoratorTextConsole ¼°Æä×ÓÀàΪÎÒÃÇµÄ ×°ÊÎÀà ¡£
¾ßÌå´úÂëÈçÏ£º
/**********************************************************************/
package decorator.interfaces;
public interface TextConsole {
public void printWords();
public void readWords();
}
/**********************************************************************/
package decorator.service;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import decorator.interfaces.TextConsole;
public class MyText implements TextConsole {
private String words;
public void printWords() {
System.out.print(words);
}
public void readWords() {
Ïà¹ØÎĵµ£º
×î½üÓöµ½Ò»¸öÐèÇóÒªÔÚlinuxÏÂÓÃjava µ÷ÓÃmysql¿Í»§¶ËÔ¶³ÌµÇ½mysql·þÎñÆ÷£¬´Ó¿Í»§¶Ë»úÆ÷µ¼Èëmysql½Å±¾£¬´Ómysql·þÎñÆ÷¶Ëµ¼³ö±íÖеÄÊý¾Ý¡£ÒÔÏÂÊÇÓõ½µÄÖ÷Òª·½·¨£º
Java ´úÂë
/**
* µ¼ÈëÊý¾Ý
* @param ½Å±¾µÄµØÖ·ºÍÃû³Æ
* @return ÊÇ·ñ³ ......
1.Listת»»³ÉΪÊý×é¡££¨ÕâÀïµÄListÊÇʵÌåÊÇArrayList)
µ÷ÓÃArrayListµÄtoArray·½·¨¡£
Àý£ºString[] arr = (String[])list.toArray(new String[size]);
2.Êý×éת»»³ÉΪList¡£
µ÷ÓÃArraysµÄasList·½·¨¡£
Àý£ºList stooges = Arrays.asList("Larry", "Moe", "Curly"); ......
Ç°Ò»ÕóÔÚ¹«Ë¾ÀïʹÓà jconsle ʱһÇÐÕý³££¬È»¶øÔÚ¼ÒÖеĻúÆ÷ÉÏÈ´³öÏÖÁ˱êÌâËùʾµÄÎÊÌ⣺
jconsole ºÍ jps ÎÞ·¨ÏÔʾ±¾µØ Java ½ø³ÌÁÐ±í¡£
µ±Ê±Ö±½ÓÀûÓà -Dcom.sun.management.jmxremote.port=port Æô¶¯Ä¿±ê java ½ø³Ì£¬²¢ÔÚ jconsole ÖÐͨ¹ý localhost:port ·½Ê½³É¹¦Á¬½ÓÉÏÄ¿±ê java ½ø³Ì¡£ÓÐÁËÕâ¸ö work around Ö®ºó£¬¶ÔÕ ......
JavaÀàÖеľ²Ì¬±äÁ¿ÔÚ³ÌÐòÔËÐÐÆڼ䣬ÆäÄÚ´æ¿Õ¼ä¶ÔËùÓиÃÀàµÄ¶ÔÏóʵÀý¶øÑÔÊǹ²ÏíµÄ£¬ÓÐЩʱºò¿ÉÒÔÈÏΪÊÇÈ«¾Ö±äÁ¿¡£Òò´ËÔÚijЩʱºòΪÁ˽ÚʡϵͳÄڴ濪Ïú¡¢¹²Ïí×ÊÔ´£¬¿ÉÒÔ½«ÀàÖеÄһЩ±äÁ¿ÉùÃ÷Ϊ¾²Ì¬±äÁ¿£¬Í¨¹ýÏÂÃæµÄÀý×Ó£¬Äã¿ÉÒÔ·¢ÏÖºÏÀíÓ¦Óþ²Ì¬±äÁ¿´øÀ´µÄºÃ´¦£º
¡¡¡¡Java´úÂë ......