第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……
}
}