´úÀíģʽ֮Javaѧϰ±Ê¼Ç11ÔÂ07ÈÕ[תÌù]
´úÀíģʽ
´úÀíģʽµÄ×÷ÓÃÊÇ£º
ΪÆäËû¶ÔÏóÌṩһÖÖ´úÀíÒÔ¿ØÖƶÔÕâ¸ö¶ÔÏóµÄ·ÃÎÊ¡£ÔÚijЩÇé¿öÏ£¬Ò»¸ö¿Í»§²»Ïë»òÕß²»ÄÜÖ±½ÓÒýÓÃÁíÒ»¸ö¶ÔÏ󣬶ø´úÀí¶ÔÏó¿ÉÒÔÔÚ¿Í»§¶ËºÍÄ¿±ê¶ÔÏóÖ®¼äÆðµ½ÖнéµÄ×÷Óá£
´úÀíģʽһ°ãÉæ¼°µ½µÄ½ÇÉ«ÓУº
³éÏó½ÇÉ«£ºÉùÃ÷Õæʵ¶ÔÏóºÍ´úÀí¶ÔÏóµÄ¹²Í¬½Ó¿Ú£»
´úÀí½ÇÉ«£º´úÀí¶ÔÏó½ÇÉ«ÄÚ²¿º¬ÓжÔÕæʵ¶ÔÏóµÄÒýÓ㬴Ӷø¿ÉÒÔ²Ù×÷Õæʵ¶ÔÏó£¬Í¬Ê±´úÀí¶ÔÏóÌṩÓëÕæʵ¶ÔÏóÏàͬµÄ½Ó¿ÚÒÔ±ãÔÚÈκÎʱ¿Ì¶¼ÄÜ´úÌæÕæʵ¶ÔÏó¡£Í¬Ê±£¬´úÀí¶ÔÏó¿ÉÒÔÔÚÖ´ÐÐÕæʵ¶ÔÏó²Ù×÷ʱ£¬¸½¼ÓÆäËûµÄ²Ù×÷£¬Ï൱ÓÚ¶ÔÕæʵ¶ÔÏó½øÐзâ×°¡£
Õæʵ½ÇÉ«£º´úÀí½ÇÉ«Ëù´ú±íµÄÕæʵ¶ÔÏó£¬ÊÇÎÒÃÇ×îÖÕÒªÒýÓõĶÔÏó¡£
ÒÔÏÂÒÔ¡¶JavaÓëģʽ¡·ÖеÄʾÀýΪÀý£º
´úÂ룺 //³éÏó½ÇÉ«£º
abstract public class Subject{
abstract public void request();
}
//Õæʵ½ÇÉ«£ºÊµÏÖÁËSubjectµÄrequest()·½·¨¡£
public class RealSubject extends Subject{
public RealSubject(){
}
public void request(){
System.out.println("from real subject.");
}
}
//´úÀí½ÇÉ«£º
public class ProxySubject extends Subject{
private RealSubject realSubject; //ÒÔÕæʵ½ÇÉ«×÷Ϊ´úÀí½ÇÉ«µÄÊôÐÔ
public ProxySubject(){
}
public void request(){ //¸Ã·½·¨·â×°ÁËÕæʵ¶ÔÏóµÄrequest·½·¨
preRequest();
if( realSubject == null ){
realSubject = new RealSubject();
}
realSubject.request(); //´Ë´¦Ö´ÐÐÕæʵ¶ÔÏóµÄrequest·½·¨
postRequest();
}
private void preRequest(){
//something you want to do before requesting
}
private void postRequest(){
//something you want to do after requesting
}
}
//¿Í»§¶Ëµ÷Óãº
Subject sub=new ProxySubject();
Sub.request();
ÓÉÒÔÉÏ´úÂë¿ÉÒÔ¿´³ö£¬¿Í»§Êµ¼ÊÐèÒªµ÷ÓõÄÊÇRealSubjectÀàµÄrequest()·½·¨£¬ÏÖÔÚÓÃProxySubjectÀ´´úÀíRealSubjectÀ࣬ͬÑù´ïµ½Ä¿µÄ£¬Í¬Ê±»¹·â×°ÁËÆäËû·½·¨(preRequest(),postRequest())£¬¿ÉÒÔ´¦ÀíһЩÆäËûÎÊÌâ¡£
ÁíÍ⣬Èç¹ûÒª°´ÕÕÉÏÊöµÄ·½·¨Ê¹ÓôúÀíģʽ£¬ÄÇôÕæʵ½ÇÉ«±ØÐëÊÇÊÂÏÈÒѾ´æÔڵģ¬²¢½«Æä×÷Ϊ´úÀí¶ÔÏóµÄÄÚ²¿ÊôÐÔ¡£µ«Ê
Ïà¹ØÎĵµ£º
»·¾³eclipse6.0 +tomcat6.0
1.´´½¨Ò»¸ö¶¯Ì¬web¹¤³Ì£ºDynamic Web Project
2.Ìîд¹¤³ÌÃû³Æºó £¬Ò»Â·next -->finish ÔÚÕâÀïÎÒ´´½¨µÄÃû³ÆΪmywebservice
3.ÔÚsrc´´½¨×Ô¼ºµÄ°ücom.zhangchaoºÍÀà Hello.java£¬ÎÒÃÇÕâÀﻹÊÇ×ö¸ö¼òµ¥µÄhelloworld¡£
ÕâÀïÖ»×ö¶ÔijÈ˽øÐÐÎʺò¡£
4.Ì ......
javaÊý¾Ý¿âÁ¬½Ó³Ø
javaÊý¾Ý¿âÁ¬½Ó³Ø
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;
import java.util.Vector;
......
±¾ÈËÍøÉÏÊÕ¼¯µÄÁ½¸öjava
¼Òô³ÌÐò,ÎÄÕ³ö´¦²»¼ÇµÃÁË.
³ÌÐò1:
import javax.sound.sampled.*;
import javax.swing.JFrame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Toolkit;
import javax.swing.JPanel;
import java.awt.event.ActionListener;
......
1.1 ²»ÓÃnew¹Ø¼ü´Ê´´½¨ÀàµÄʵÀý
ÓÃnew¹Ø¼ü´Ê´´½¨ÀàµÄʵÀýʱ£¬¹¹Ô캯ÊýÁ´ÖеÄËùÓй¹Ô캯Êý¶¼»á±»×Ô¶¯µ÷Óᣵ«Èç¹ûÒ»¸ö¶ÔÏóʵÏÖÁËCloneable½Ó¿Ú£¬ÎÒÃÇ¿ÉÒÔµ÷ÓÃËüµÄclone()·½·¨¡£clone()·½·¨²»»áµ÷ÓÃÈκÎÀ๹Ô캯Êý¡£
ÔÚʹÓÃÉè¼Æģʽ£¨Design Pattern£©µÄ³¡ºÏ£¬Èç¹ûÓÃFactoryģʽ´´½¨¶ÔÏó£¬Ôò¸ÄÓÃclone()·½·¨´´½¨Ðµ ......