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() {
Ïà¹ØÎĵµ£º
import java.awt.*;
import javax.swing.*;
import java.util.Date;
import java.awt.*;
class Time extends JFrame implements Runnable{//ʵÏÖ½Ó¿Ú
Thread clockThread;
JLabel jLabel=new JLabel();
public Time()
{
Container con=this.getContentPane() ......
JCP SE/EE Ö´ÐÐίԱ»á
Õýʽ½ÓÊÜÁË
JSR 330
—— Dependency Injection for Java¡£¸Ã¹æ·¶ÓÚ ½ñÄê 5 Ô 9 ÈÕ
ÓÉ Google µÄ Bob Lee ÒÔ¼° SpringSource µÄ Rod Johnson ×÷Ϊ¹æ·¶Áìµ¼Ìá½»¸ø JCP£¬ÏÖÔÚÒѾÕýʽ·¢²¼£¬²»µÃ²»¸Ð̾¸Ã¹æ·¶±ê×¼»¯¹ý³ÌÖ®¿ì¡£ÔÚ ×îÖÕͶƱ½á¹ûÖÐ
£¬14 Ʊͨ¹ý£¬1 ƱδͶ£¬1 Ʊ·´¶Ô¡£
J ......
1.¼ÆËãijһÔ·ݵÄ×î´óÌìÊý
Calendar time=Calendar.getInstance();
time.clear();
time.set(Calendar.YEAR,year);
time.set(Calendar.MONTH,i-1);//×¢Òâ,Calendar¶ÔÏóĬÈÏÒ»ÔÂΪ0
int day=time.getActualMaximum(Calendar.DAY_OF_MONTH);//±¾Ô·ݵÄÌìÊý ......
1 JDK5.0°üÀ¨µÄµ÷ÊÔ¹¤¾ß
ÎÒÃÇÔÚÕâÀï¶ÔJDK5.0µÄµ÷ÊÔ¹¤¾ß×ö´óÖµĸÅÄîÐԵĽéÉÜ£¬È»ºóÏ£Íûͨ¹ý½éÉÜÎÒ×Ô¼ºÔÚʵ¼Ê¹¤×÷ÖÐʹÓÃÕâЩ¹¤¾ß½â¾öÎÊÌâµÄʵÀýÀ´Èôó¼Ò¶ÔÕâЩ¹¤¾ßÓиüÉîÈëµÄÁ˽⡣
¡¡JDK5.0ÀïÃæ¼ÓÈëÁËjstack, jconsole, jinfo, jmap, jdb, jstat, jps, ÏÂÃæ¶ÔÕâЩ¹¤¾ß×ö¼òµ¥½éÉÜ£º
¡¡jstack -- Èç¹ûjava³Ì ......
Ç°Ò»ÕóÔÚ¹«Ë¾ÀïʹÓà jconsle ʱһÇÐÕý³££¬È»¶øÔÚ¼ÒÖеĻúÆ÷ÉÏÈ´³öÏÖÁ˱êÌâËùʾµÄÎÊÌ⣺
jconsole ºÍ jps ÎÞ·¨ÏÔʾ±¾µØ Java ½ø³ÌÁÐ±í¡£
µ±Ê±Ö±½ÓÀûÓà -Dcom.sun.management.jmxremote.port=port Æô¶¯Ä¿±ê java ½ø³Ì£¬²¢ÔÚ jconsole ÖÐͨ¹ý localhost:port ·½Ê½³É¹¦Á¬½ÓÉÏÄ¿±ê java ½ø³Ì¡£ÓÐÁËÕâ¸ö work around Ö®ºó£¬¶ÔÕ ......