簡體中文 | 繁體中文

大話設計模式-----第3章


護花狀元在現代 至尊兵王 千金來襲:侯門妻不可欺 折眉彎 穿越清朝記事之媱兒 賤命 重生八側福晉 火影之宇智波水月 縱橫異界之系統無敵 色中仙 冷血女魔和她的帝王男寵:妖臨天下 網遊之GM也瘋狂 榮耀之冠 盜墓筆記續集 陰夫難纏 如果,不買 我們的青春該怎樣 錯位 特種兵穿越之大宋親王 薄情女孩:痞女征服黑老大
第3章

這天大B問小A:“怎樣設計可複用的面向物件軟體?”

小A:“師兄你這是考我麼?”

大B:“啥啊?我這是想看你在學校是不是真學到了東西。”

小A:“得得得,那我就說說吧!設計模式是一套被反覆使用、多數人知曉的、經過分類編目的、程式碼設計經驗的總結。使用設計模式是為了可重用程式碼、讓程式碼更容易被他人理解、保證程式碼可靠性。設計模式於己於他人於系統都是多贏的,設計模式使程式碼編制真正工程化,設計模式是軟體工程的基石,如同大廈的一塊塊磚石一樣。”

大B:“我再考考你,用C++、Java、C#或VB.NET任意一種面嚮物件語言實現一個簡單程式。”

小A不到幾分鐘就給大B一個程式。

/*

*@(#)Blah.java1.8299/03/18

*Copyright(c)1994-1999SunMicrosystems,Inc.

*901SanAntonioRoad,PaloAlto,California,94303,U.S.A.

*Allrightsreserved.

*ThissoftwareistheconfidentialandproprietaryinformationofSun

*Microsystems,Inc.(“ConfidentialInformation”).Youshallnot

*disclosesuchConfidentialInformationandshalluseitonlyin

*accordancewiththetermsofthelicenseagreementyouenteredinto

*withSun.

*/

packagejava.blah;

importjava.blah.blahdy.BlahBlah;

/**

*Classdescriptiongoeshere.

*

*@version1.82

*@authorFirstnameLastname

*/

publicclassBlahextendsSomeClass{

/*Aclassimplementationmentcangohere.*/

*

*classVar2documentationmentthathappenstobe

*morethanonelinelong

*/

privatestaticObjectclassVar2;

/**instanceVar1documentationment*/

publicObjectinstanceVar1;

/**instanceVar2documentationment*/

protectedintinstanceVar2;

/**instanceVar3documentationment*/

privateObject[]instanceVar3;

/**

publicclassBlahextendsSomeClass{

/*Aclassimplementationmentcangohere.*/

*

*classVar2documentationmentthathappenstobe

*morethanonelinelong

*/

privatestaticObjectclassVar2;

/**instanceVar1documentationment*/

publicObjectinstanceVar1;

/**instanceVar2documentationment*/

protectedintinstanceVar2;

/**instanceVar3documentationment*/

privateObject[]instanceVar3;

/**

*……constructorBlahdocumentationment……

*/

publicBlah(){

//……implementationgoeshere……

}

/**

*……methoddoSomethingdocumentationment……

*/

publicvoiddoSomething(){

//……implementationgoeshere……

}

/**

*……methoddoSomethingElsedocumentationment……

*@paramsomeParamdescription

*/

publicvoiddoSomethingElse(ObjectsomeParam){

//……implementationgoeshere……

}

}

推薦小說