锘??xml version="1.0" encoding="utf-8" standalone="yes"?>中文字幕亚洲精品无码,亚洲黄色三级视频,亚洲第一页中文字幕http://www.tkk7.com/nikita/category/39099.htmlzh-cnSat, 23 May 2009 23:00:36 GMTSat, 23 May 2009 23:00:36 GMT60璁捐妯″紡涔婳bserver - Java璁捐妯″紡http://www.tkk7.com/nikita/archive/2008/10/08/233193.htmlpicture talkpicture talkWed, 08 Oct 2008 10:06:00 GMThttp://www.tkk7.com/nikita/archive/2008/10/08/233193.htmlhttp://www.tkk7.com/nikita/comments/233193.htmlhttp://www.tkk7.com/nikita/archive/2008/10/08/233193.html#Feedback0http://www.tkk7.com/nikita/comments/commentRss/233193.htmlhttp://www.tkk7.com/nikita/services/trackbacks/233193.html Java娣卞叆鍒頒竴瀹氱▼搴?灝變笉鍙伩鍏嶇殑紕板埌璁捐妯″紡(design pattern)榪欎竴姒傚康,浜嗚В璁捐妯″紡,灝嗕嬌鑷繁瀵筳ava涓殑鎺ュ彛鎴栨娊璞$被搴旂敤鏈夋洿娣辯殑鐞嗚В.璁捐妯″紡鍦╦ava鐨勪腑鍨嬬郴緇熶腑搴旂敤騫挎硾,閬靛驚涓瀹氱殑緙栫▼妯″紡,鎵嶈兘浣胯嚜宸辯殑浠g爜渚夸簬鐞嗚В,鏄撲簬浜ゆ祦,Observer(瑙傚療鑰?妯″紡鏄瘮杈冨父鐢ㄧ殑涓涓ā寮?灝ゅ叾鍦ㄧ晫闈㈣璁′腑搴旂敤騫挎硾,鑰屾湰绔欐墍鍏蟲敞鐨勬槸Java鍦ㄧ數瀛愬晢鍔$郴緇熶腑搴旂敤,鍥犳鎯充粠鐢靛瓙鍟嗗姟瀹炰緥涓垎鏋怬bserver鐨勫簲鐢?

铏界劧緗戜笂鍟嗗簵褰㈠紡澶氭牱,姣忎釜绔欑偣鏈夎嚜宸辯殑鐗硅壊,浣嗕篃鏈夊叾涓鑸殑鍏辨?鍗曞氨"鍟嗗搧鐨勫彉鍖?浠ヤ究鍙婃椂閫氱煡璁㈡埛"榪欎竴鐐?鏄緢澶氱綉涓婂晢搴楀叡鏈夌殑妯″紡,榪欎竴妯″紡綾諱技Observer patern.

鍏蜂綋鐨勮,濡傛灉緗戜笂鍟嗗簵涓晢鍝佸湪鍚嶇О 浠鋒牸絳夋柟闈㈡湁鍙樺寲,濡傛灉緋葷粺鑳借嚜鍔ㄩ氱煡浼氬憳,灝嗘槸緗戜笂鍟嗗簵鍖哄埆浼犵粺鍟嗗簵鐨勪竴澶х壒鑹?榪欏氨闇瑕佸湪鍟嗗搧product涓姞鍏bserver榪欐牱瑙掕壊,浠ヤ究product緇嗚妭鍙戠敓鍙樺寲鏃?Observer鑳借嚜鍔ㄨ瀵熷埌榪欑鍙樺寲,騫惰兘榪涜鍙婃椂鐨剈pdate鎴杗otify鍔ㄤ綔.

Java鐨凙PI榪樹負涓烘垜浠彁渚涚幇鎴愮殑Observer鎺ュ彛Java.util.Observer.鎴戜滑鍙鐩存帴浣跨敤瀹冨氨鍙互.

鎴戜滑蹇呴』extends Java.util.Observer鎵嶈兘鐪熸浣跨敤瀹?
1.鎻愪緵Add/Delete observer鐨勬柟娉?
2.鎻愪緵閫氱煡(notisfy) 鎵鏈塷bserver鐨勬柟娉?

//浜у搧綾?鍙緵Jsp鐩存帴浣跨敤UseBean璋冪敤 璇ョ被涓昏鎵ц浜у搧鏁版嵁搴撴彃鍏?鏇存柊
public class product extends Observable{

銆銆private String name;
銆銆private float price;

銆銆public String getName(){ return name;}
銆銆public void setName(){
銆銆 this.name=name;
銆銆//璁劇疆鍙樺寲鐐?
銆銆 setChanged();
銆銆 notifyObservers(name);

銆銆}銆銆銆

銆銆public float getPrice(){ return price;}
銆銆public void setPrice(){
銆銆 this.price=price;
銆銆//璁劇疆鍙樺寲鐐?br />銆銆 setChanged();
銆銆 notifyObservers(new Float(price));

銆銆}

銆銆//浠ヤ笅鍙互鏄暟鎹簱鏇存柊 鎻掑叆鍛戒護.
銆銆public void saveToDb(){
銆銆.....................

}


鎴戜滑娉ㄦ剰鍒?鍦╬roduct綾諱腑 鐨剆etXXX鏂規硶涓?鎴戜滑璁劇疆浜?notify(閫氱煡)鏂規硶, 褰揓sp琛ㄥ崟璋冪敤setXXX(濡備綍璋冪敤瑙佹垜鐨?a target="_blank">鍙﹀涓綃囨枃绔?/font>),瀹為檯涓婂氨瑙﹀彂浜唍otisfyObservers鏂規硶,榪欏皢閫氱煡鐩稿簲瑙傚療鑰呭簲璇ラ噰鍙栬鍔ㄤ簡.

涓嬮潰鐪嬬湅榪欎簺瑙傚療鑰呯殑浠g爜,浠栦滑絀剁珶閲囧彇浜嗕粈涔堣鍔?

//瑙傚療鑰匩ameObserver涓昏鐢ㄦ潵瀵逛駭鍝佸悕縐?name)榪涜瑙傚療鐨?br />public class NameObserver implements Observer{

銆銆private String name=null;

銆銆public void update(Observable obj,Object arg){

銆銆銆銆if (arg instanceof String){

銆銆銆銆 name=(String)arg;
銆銆銆銆 //浜у搧鍚嶇О鏀瑰彉鍊煎湪name涓?br />銆銆銆銆 System.out.println("NameObserver :name changet to "+name);

銆銆銆銆}

銆銆}

}

//瑙傚療鑰匬riceObserver涓昏鐢ㄦ潵瀵逛駭鍝佷環鏍?price)榪涜瑙傚療鐨?br />public class PriceObserver implements Observer{

銆銆private float price=0;

銆銆public void update(Observable obj,Object arg){

銆銆銆銆if (arg instanceof Float){

銆銆銆銆 price=((Float)arg).floatValue();
銆銆
銆銆銆銆 System.out.println("PriceObserver :price changet to "+price);

銆銆銆銆}

銆銆}

}


Jsp涓垜浠彲浠ユ潵姝e紡鎵ц榪欐瑙傚療鑰呯▼搴?

<jsp:useBean id="product" scope="session" class="Product" />
<jsp:setProperty name="product" property="*" />

<jsp:useBean id="nameobs" scope="session" class="NameObserver" />
<jsp:setProperty name="product" property="*" />

<jsp:useBean id="priceobs" scope="session" class="PriceObserver" />
<jsp:setProperty name="product" property="*" />

<%

if (request.getParameter("save")!=null)
{
銆銆product.saveToDb();


銆銆out.println("浜у搧鏁版嵁鍙樺姩 淇濆瓨! 騫跺凡緇忚嚜鍔ㄩ氱煡瀹㈡埛");

}else{

銆銆//鍔犲叆瑙傚療鑰?br />銆銆product.addObserver(nameobs);

銆銆product.addObserver(priceobs);

%>

銆銆//request.getRequestURI()鏄駭鐢熸湰jsp鐨勭▼搴忓悕,灝辨槸鑷繁璋冪敤鑷繁
銆銆<form action="<%=request.getRequestURI()%>" method=post>

銆銆<input type=hidden name="save" value="1">
銆銆浜у搧鍚嶇О:<input type=text name="name" >
銆銆浜у搧浠鋒牸:<input type=text name="price">
銆銆<input type=submit>

銆銆</form>

<%

}

%>

鎵ц鏀?span lang="EN-US">Jsp紼嬪簭,浼氬嚭鐜頒竴涓〃鍗曞綍鍏ョ晫闈? 闇瑕佽緭鍏ヤ駭鍝佸悕縐?浜у搧浠鋒牸, 鐐規寜Submit鍚?榪樻槸鎵ц璇sp鐨?br />if (request.getParameter("save")!=null)涔嬮棿鐨勪唬鐮?


鐢變簬榪欓噷浣跨敤浜嗘暟鎹甹avabeans鐨勮嚜鍔ㄨ祴鍊兼蹇?瀹為檯紼嬪簭鑷姩鎵ц浜唖etName setPrice璇彞.浣犱細鍦ㄦ湇鍔″櫒鎺у埗鍙頒腑鍙戠幇涓嬮潰淇℃伅::

NameObserver :name changet to ?????(Jsp琛ㄥ崟涓緭鍏ョ殑浜у搧鍚嶇О)

PriceObserver :price changet to ???(Jsp琛ㄥ崟涓緭鍏ョ殑浜у搧浠鋒牸);

榪欒鏄庤瀵熻呭凡緇忓湪琛屽姩浜?span lang="EN-US">.!!
鍚屾椂浣犱細鍦ㄦ墽琛宩sp鐨勬祻瑙堝櫒绔緱鍒頒俊鎭?

浜у搧鏁版嵁鍙樺姩 淇濆瓨! 騫跺凡緇忚嚜鍔ㄩ氱煡瀹㈡埛

涓婃枃鐢變簬浣跨敤jsp姒傚康,闅愬惈寰堝鑷姩鍔ㄤ綔,鐜板皢璋冪敤瑙傚療鑰呯殑Java浠g爜鍐欏涓?

public class Test {

銆銆public static void main(String args[]){

Product product=new Product();

NameObserver nameobs=new NameObserver();
PriceObserver priceobs=new PriceObserver();

//鍔犲叆瑙傚療鑰?br />product.addObserver(nameobs);
product.addObserver(priceobs);

product.setName("姍樺瓙綰簡");
product.setPrice(9.22f);

銆銆}

}

浣犱細鍦ㄥ彂鐜頒笅闈俊鎭?span lang="EN-US">::

NameObserver :name changet to 姍樺瓙綰簡

PriceObserver :price changet to 9.22

榪欒鏄庤瀵熻呭湪琛屽姩浜?span lang="EN-US">.!!

鏉ユ簮 錛?http://book.javanb.com/java-design-patterns/Observer.html



]]>
璁捐妯″紡涔婥omposite - Java璁捐妯″紡http://www.tkk7.com/nikita/archive/2008/10/08/233172.htmlpicture talkpicture talkWed, 08 Oct 2008 08:53:00 GMThttp://www.tkk7.com/nikita/archive/2008/10/08/233172.htmlhttp://www.tkk7.com/nikita/comments/233172.htmlhttp://www.tkk7.com/nikita/archive/2008/10/08/233172.html#Feedback0http://www.tkk7.com/nikita/comments/commentRss/233172.htmlhttp://www.tkk7.com/nikita/services/trackbacks/233172.html Composite瀹氫箟 :
灝嗗璞′互鏍戝艦緇撴瀯緇勭粐璧鋒潵,浠ヨ揪鎴愨滈儴鍒嗭紞鏁翠綋鈥?鐨勫眰嬈$粨鏋勶紝浣垮緱瀹㈡埛绔鍗曚釜瀵硅薄鍜岀粍鍚堝璞$殑浣跨敤鍏鋒湁涓鑷存?

Composite姣旇緝瀹規槗鐞嗚В錛屾兂鍒癈omposite灝卞簲璇ユ兂鍒版爲褰㈢粨鏋勫浘銆傜粍鍚堜綋鍐呰繖浜涘璞¢兘鏈夊叡鍚屾帴鍙?褰撶粍鍚堜綋涓涓璞$殑鏂規硶琚皟鐢ㄦ墽琛屾椂錛孋omposite灝嗛亶鍘?Iterator)鏁翠釜鏍戝艦緇撴瀯,瀵繪壘鍚屾牱鍖呭惈榪欎釜鏂規硶鐨勫璞″茍瀹炵幇璋冪敤鎵ц銆傚彲浠ョ敤鐗典竴鍔ㄧ櫨鏉ュ艦瀹廣?o:p>

鎵浠?span lang="EN-US">Composite妯″紡浣跨敤鍒癐terator妯″紡錛屽拰Chain of Responsibility妯″紡綾諱技銆?o:p>

Composite濂藉 :
1.浣垮鎴風璋冪敤綆鍗曪紝瀹㈡埛绔彲浠ヤ竴鑷寸殑浣跨敤緇勫悎緇撴瀯鎴栧叾涓崟涓璞★紝鐢ㄦ埛灝變笉蹇呭叧緋昏嚜宸卞鐞嗙殑鏄崟涓璞¤繕鏄暣涓粍鍚堢粨鏋勶紝榪欏氨綆鍖栦簡瀹㈡埛绔唬鐮併?br />2.鏇村鏄撳湪緇勫悎浣撳唴鍔犲叆瀵硅薄閮ㄤ歡. 瀹㈡埛绔笉蹇呭洜涓哄姞鍏ヤ簡鏂扮殑瀵硅薄閮ㄤ歡鑰屾洿鏀逛唬鐮併?o:p>

濡備綍浣跨敤Composite?
棣栧厛瀹氫箟涓涓帴鍙f垨鎶借薄綾伙紝榪欐槸璁捐妯″紡閫氱敤鏂瑰紡浜嗭紝鍏朵粬璁捐妯″紡瀵規帴鍙e唴閮ㄥ畾涔夐檺鍒朵笉澶氾紝Composite鍗存湁涓瀹氾紝閭e氨鏄鍦ㄦ帴鍙e唴閮ㄥ畾涔変竴涓敤浜庤闂拰綆$悊Composite緇勫悎浣撶殑瀵硅薄浠紙鎴栫О閮ㄤ歡Component錛?

涓嬮潰鐨勪唬鐮佹槸浠ユ娊璞$被瀹氫箟錛屼竴鑸敖閲忕敤鎺ュ彛interface,

public abstract class Equipment
{
銆銆private String name;
銆銆//緗戠粶浠鋒牸
銆銆public abstract double netPrice();
銆銆//鎶樻墸浠鋒牸
銆銆public abstract double discountPrice();
銆銆//澧炲姞閮ㄤ歡鏂規硶銆銆
銆銆public boolean add(Equipment equipment) { return false; }
銆銆//鍒犻櫎閮ㄤ歡鏂規硶
銆銆public boolean remove(Equipment equipment) { return false; }
銆銆//娉ㄦ剰榪欓噷錛岃繖閲屽氨鎻愪緵涓縐嶇敤浜庤闂粍鍚堜綋綾葷殑閮ㄤ歡鏂規硶銆?br />銆銆public Iterator iter() { return null; }
銆銆
銆銆public Equipment(final String name) { this.name=name; }
}

鎶借薄綾?span lang="EN-US">Equipment灝辨槸Component瀹氫箟錛屼唬琛ㄧ潃緇勫悎浣撶被鐨勫璞′滑,Equipment涓畾涔夊嚑涓叡鍚岀殑鏂規硶銆?o:p>

public class Disk extends Equipment
{
銆銆public Disk(String name) { super(name); }
銆銆//瀹氫箟Disk緗戠粶浠鋒牸涓?
銆銆public double netPrice() { return 1.; }
銆銆//瀹氫箟浜哾isk鎶樻墸浠鋒牸鏄?.5 瀵規姌銆?br />銆銆public double discountPrice() { return .5; }
}

Disk鏄粍鍚堜綋鍐呯殑涓涓璞★紝鎴栫О涓涓儴浠訛紝榪欎釜閮ㄤ歡鏄釜鍗曠嫭鍏冪礌( Primitive)銆?br />榪樻湁涓縐嶅彲鑳芥槸錛屼竴涓儴浠朵篃鏄竴涓粍鍚堜綋錛屽氨鏄榪欎釜閮ㄤ歡涓嬮潰榪樻湁'鍎垮瓙'錛岃繖鏄爲褰㈢粨鏋勪腑閫氬父鐨勬儏鍐碉紝搴旇姣旇緝瀹規槗鐞嗚В銆傜幇鍦ㄦ垜浠厛瑕佸畾涔夎繖涓粍鍚堜綋錛?o:p>

abstract class CompositeEquipment extends Equipment
{
銆銆private int i=0;
銆銆//瀹氫箟涓涓猇ector 鐢ㄦ潵瀛樻斁'鍎垮瓙'
銆銆private Lsit equipment=new ArrayList();

銆銆public CompositeEquipment(String name) { super(name); }

銆銆public boolean add(Equipment equipment) {
銆銆銆銆 this.equipment.add(equipment);
銆銆銆銆 return true;
銆銆 }

銆銆public double netPrice()
銆銆{
銆銆銆銆double netPrice=0.;
銆銆銆銆Iterator iter=equipment.iterator();
銆銆銆銆for(iter.hasNext())
銆銆銆銆銆銆netPrice+=((Equipment)iter.next()).netPrice();
銆銆銆銆return netPrice;
銆銆}

銆銆public double discountPrice()
銆銆{
銆銆銆銆double discountPrice=0.;
銆銆銆銆Iterator iter=equipment.iterator();
銆銆銆銆for(iter.hasNext())
銆銆銆銆銆銆discountPrice+=((Equipment)iter.next()).discountPrice();
銆銆銆銆return discountPrice;
銆銆}
銆銆

銆銆//娉ㄦ剰榪欓噷錛岃繖閲屽氨鎻愪緵鐢ㄤ簬璁塊棶鑷繁緇勫悎浣撳唴鐨勯儴浠舵柟娉曘?br />銆銆//涓婇潰dIsk 涔嬫墍浠ユ病鏈夛紝鏄洜涓篋isk鏄釜鍗曠嫭(Primitive)鐨勫厓绱?
銆銆public Iterator iter()
銆銆{
銆銆銆銆return equipment.iterator() ;
銆銆{
銆銆//閲嶈澆Iterator鏂規硶
銆銆 public boolean hasNext() { return i<equipment.size(); }
銆銆//閲嶈澆Iterator鏂規硶
銆銆 public Object next()
銆銆 {
銆銆銆銆if(hasNext())
銆銆銆銆銆銆 return equipment.elementAt(i++);
銆銆銆銆else
銆銆 銆銆 銆 throw new NoSuchElementException();
銆銆 }
銆銆

}

涓婇潰CompositeEquipment緇ф壙浜咵quipment,鍚屾椂涓鴻嚜宸遍噷闈㈢殑瀵硅薄浠彁渚涗簡澶栭儴璁塊棶鐨勬柟娉?閲嶈澆浜咺terator,Iterator鏄疛ava鐨凜ollection鐨勪竴涓帴鍙o紝鏄疘terator妯″紡鐨勫疄鐜?

鎴戜滑鍐嶇湅鐪?span lang="EN-US">CompositeEquipment鐨勪袱涓叿浣撶被:鐩樼洅Chassis鍜岀瀛怌abinet錛岀瀛愰噷闈㈠彲浠ユ斁寰堝涓滆タ錛屽搴曟澘錛岀數婧愮洅錛岀‖鐩樼洅絳夛紱鐩樼洅閲岄潰鍙互鏀句竴浜涘皬璁懼錛屽紜洏 杞┍絳夈傛棤鐤戣繖涓や釜閮芥槸灞炰簬緇勫悎浣撴ц川鐨勩?o:p>

public class Chassis extends CompositeEquipment
{
銆銆 public Chassis(String name) { super(name); }
銆銆 public double netPrice() { return 1.+super.netPrice(); }
銆銆 public double discountPrice() { return .5+super.discountPrice(); }
}

public class Cabinet extends CompositeEquipment
{
銆銆 public Cabinet(String name) { super(name); }
銆銆 public double netPrice() { return 1.+super.netPrice(); }
銆銆 public double discountPrice() { return .5+super.discountPrice(); }
}

鑷蟲鎴戜滑瀹屾垚浜嗘暣涓?span lang="EN-US">Composite妯″紡鐨勬灦鏋勩?o:p>

鎴戜滑鍙互鐪嬬湅瀹㈡埛绔皟鐢?span lang="EN-US">Composote浠g爜:

Cabinet cabinet=new Cabinet("Tower");

Chassis chassis=new Chassis("PC Chassis");
//灝哖C Chassis瑁呭埌Tower涓?(灝嗙洏鐩掕鍒扮瀛愰噷)
cabinet.add(chassis);
//灝嗕竴涓?0GB鐨勭‖鐩樿鍒?PC Chassis (灝嗙‖鐩樿鍒扮洏鐩掗噷)
chassis.add(new Disk("10 GB"));

//璋冪敤 netPrice()鏂規硶;
System.out.println("netPrice="+cabinet.netPrice());
System.out.println("discountPrice="+cabinet.discountPrice());

涓婇潰璋冪敤鐨勬柟娉?span lang="EN-US">netPrice()鎴杁iscountPrice()錛屽疄闄呬笂Composite浣跨敤Iterator閬嶅巻浜嗘暣涓爲褰㈢粨鏋?瀵繪壘鍚屾牱鍖呭惈榪欎釜鏂規硶鐨勫璞″茍瀹炵幇璋冪敤鎵ц.

Composite鏄釜寰堝閥濡欎綋鐜版櫤鎱х殑妯″紡錛屽湪瀹為檯搴旂敤涓紝濡傛灉紕板埌鏍戝艦緇撴瀯錛屾垜浠氨鍙互灝濊瘯鏄惁鍙互浣跨敤榪欎釜妯″紡銆?o:p>

浠ヨ鍧涗負渚嬶紝涓涓増(forum)涓湁寰堝甯栧瓙(message),榪欎簺甯栧瓙鏈夊師濮嬭創錛屾湁瀵瑰師濮嬭創鐨勫洖搴旇創錛屾槸涓吀鍨嬬殑鏍戝艦緇撴瀯錛岄偅涔堝綋鐒跺彲浠ヤ嬌鐢–omposite妯″紡錛岄偅涔堟垜浠繘鍏ive涓湅鐪嬶紝鏄浣曞疄鐜扮殑.

Jive瑙e墫
鍦↗ive涓?ForumThread鏄疐orumMessages鐨勫鍣╟ontainer(緇勫悎浣?.涔熷氨鏄錛孎orumThread綾諱技鎴戜滑涓婁緥涓殑 CompositeEquipment.瀹冨拰messages鐨勫叧緋誨鍥撅細
[thread]
銆銆 |- [message]
銆銆 |- [message]
銆銆 銆銆 |- [message]
銆銆 銆銆 |- [message]
銆銆 銆銆 銆銆 |- [message]

鎴戜滑鍦?span lang="EN-US">ForumThread鐪嬪埌濡備笅浠g爜錛?o:p>

public interface ForumThread {
銆銆 ....
銆銆 public void addMessage(ForumMessage parentMessage, ForumMessage newMessage)
銆銆 銆銆 銆銆 throws UnauthorizedException;

銆銆 public void deleteMessage(ForumMessage message)
銆銆 銆銆 銆銆 throws UnauthorizedException;

銆銆
銆銆 public Iterator messages();
銆銆 銆銆 ....

}

綾諱技CompositeEquipment, 鎻愪緵鐢ㄤ簬璁塊棶鑷繁緇勫悎浣撳唴鐨勯儴浠舵柟娉? 澧炲姞 鍒犻櫎 閬嶅巻.

緇撳悎鎴戠殑鍏朵粬妯″紡涓Jive鐨勫垎鏋愶紝鎴戜滑宸茬粡鍩烘湰澶т綋鐞嗚В浜咼ive璁哄潧浣撶郴鐨勬鏋訛紝濡傛灉浣犱箣鍓嶄笉鐞嗚В璁捐妯″紡錛岃岀洿鎺ュ幓鐪婮ive婧愪唬鐮侊紝浣犺偗瀹氭棤娉曠湅鎳傘?br />
:)

鏉ユ簮錛?http://book.javanb.com/java-design-patterns/Composite.html



]]>
The PathProxy pattern : Persisting complex associationshttp://www.tkk7.com/nikita/archive/2008/10/04/232356.htmlpicture talkpicture talkSat, 04 Oct 2008 11:09:00 GMThttp://www.tkk7.com/nikita/archive/2008/10/04/232356.htmlhttp://www.tkk7.com/nikita/comments/232356.htmlhttp://www.tkk7.com/nikita/archive/2008/10/04/232356.html#Feedback0http://www.tkk7.com/nikita/comments/commentRss/232356.htmlhttp://www.tkk7.com/nikita/services/trackbacks/232356.htmlPathProxy is a design pattern for persisting complex relationships without cluttering up your database.

When your class relationships require pathing knowledge, that is , knowledge about a number of related objects, then the standard "many - to" associations wont cut it, The PathProxy class is an abstraction of such relationships, allowing you to manage, persist, and extend them without complicating the classes themselves, and without a proliferation of lookup tables.

The fundamental idea is this聽: create class that can point to any entity in the system, and that also can reference its own class as a parent, With this class, you create a tree structure that maintains the interrelationships outside of the referenced objects. Building a JPA mapping around this class requires some though, but is quite powerful.

Path-Specific relationships

The
PathProxy solution applies in any situation where an entity can appear as an association of another entity type, but only for a specific path. I refer to such relationships as path specific. E is a child of D, but only for the path A-->B-->C-->D-->E.On another path, D might have no children (A-->B-->Q-->D) or might have a different child or children(A-->B-->X-->D-->Z)

As an example, imagine a development team consisting of a project manager named Johnie and two developers, Robert and Mukunda. On project A, Johnie leads Robert and on Project B, Johnie leads Mukunda. This is a somewhat contrived example, but not an uncommon scenario in the world of corporate structures. In the real world, you might have the efficiency of the same process in different business locations, or the actions taken in response to the same event by different teams

PathProxy.jpg

When to use PathProxy?

You have many entities whose interrelationships are complex and require knowledge of other relationships. Creating explicit objects to represent these types of聽 relationships becomes burdensome. This is expecially true if the objects must be persisted, creating a proliferation of database tables.

Consider PathProxy if , Your system design calls for a number of casses whose sole or primary function is to model the relationships between other objects.

Using PathProxy is more complicated than using聽 simple objects to represent relationships, so consider your particular situation. If you have few relationships to store and they are not too complicated, PathProxy may not be the right choice. On the other hand, once you reach a certain level of relationship complexity, using PathProxy will greatly simplify your overall system design. Beijng able to reuse the same machnaism over and over again is also a huge time-saver.


鏉ヨ嚜 : http://www.javaworld.com/javaworld/jw-07-2008/jw-07-pathproxy.html?page=1



]]>
主站蜘蛛池模板: 亚洲人成日本在线观看| 亚洲高清在线mv| 黄色a级免费网站| 国产免费av一区二区三区| 亚洲中文字幕乱码熟女在线| 丁香花免费高清视频完整版| 亚洲人成图片网站| 成年午夜视频免费观看视频| 中文字幕乱码亚洲无线三区| 免费高清在线影片一区| 亚洲成a∧人片在线观看无码| 免费一级做a爰片性色毛片| 特黄aa级毛片免费视频播放| 国产成人综合亚洲亚洲国产第一页 | 亚洲国产精品综合久久网各| 亚州免费一级毛片| 亚洲最大的成人网| 免费一级特黄特色大片在线观看| 亚美影视免费在线观看| 亚洲AV无码精品无码麻豆| 1区2区3区产品乱码免费| 亚洲卡一卡二卡乱码新区| 免费在线观看亚洲| 91视频免费观看高清观看完整| 亚洲AV无码久久精品色欲| 啦啦啦完整版免费视频在线观看 | 野花高清在线电影观看免费视频| 亚洲乱亚洲乱妇无码| 亚洲日韩国产成网在线观看 | 九九精品免费视频| 亚洲av综合av一区二区三区| 久久亚洲国产成人精品无码区| 777成影片免费观看| 亚洲av无码成人精品区一本二本| 亚洲综合熟女久久久30p| 免费国产成人高清在线观看网站| 久久精品国产亚洲AV电影网| 国产∨亚洲V天堂无码久久久| 免费可以在线看A∨网站| 一级特级女人18毛片免费视频| 亚洲欧洲第一a在线观看|