这天大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……
}
}