购买
下载掌阅APP,畅读海量书库
立即打开
畅读海量书库
扫码下载掌阅APP

1.2 什么是设计模式

这天大B问小A:“怎样设计可复用的面向对象软件?”

小A:“靠,师兄你这是考我么?”

大B:“啥啊?我这是想看你在学校是不是真学到了东西。”

小A:“得得得,那我就说说吧。设计模式是一套被反复使用、多数人知晓的、经过分类编目的、代码设计经验的总结。使用设计模式是为了可重用代码、让代码更容易被他人理解、保证代码可靠性。设计模式于己于他人于系统都是多赢的,设计模式使代码编制真正工程化,设计模式是软件工程的基石,如同大厦的一块块砖石一样。”

大B:“我再考考你,用C++、Java、C#或VB.NET任意一种面向对象语言实现一个简单程序。”

小A不到几分钟就给大B一个程序。 4xR+HfI4wUhrBdu+KRpxl6zc0qeqA51BEhF4qWfHCIRm2HWgbxryJhxiGQmL7/CQ

/*
* @(#)Blah.java        1.82 99/03/18
* Copyright (c) 1994-1999 Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
* All rights reserved.
* This software is the confidential and proprietary information of Sun
* Microsystems, Inc. ("Confidential Information").  You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Sun.
*/
package java.blah;
import java.blah.blahdy.BlahBlah;
/**
* Class description goes here.
*
* @version   1.82 18 Mar 1999
* @author   Firstname Lastname
*/
public class Blah extends SomeClass {
/* A class implementation comment can go here. */
*
* classVar2 documentation comment that happens to be
* more than one line long
*/
private static Object classVar2;
/** instanceVar1 documentation comment */
public Object instanceVar1;
/** instanceVar2 documentation comment */
protected int instanceVar2;
/** instanceVar3 documentation comment */
private Object[] instanceVar3;
/**
public class Blah extends SomeClass {
/* A class implementation comment can go here. */
*
* classVar2 documentation comment that happens to be
* more than one line long
*/
private static Object classVar2;
/** instanceVar1 documentation comment */
public Object instanceVar1;
/** instanceVar2 documentation comment */
protected int instanceVar2;
/** instanceVar3 documentation comment */
private Object[] instanceVar3;
/**
* ...constructor Blah documentation comment...
*/
public Blah() {
// ...implementation goes here...
}
/**
* ...method doSomething documentation comment...
*/
public void doSomething() {
// ...implementation goes here...
}
/**
* ...method doSomethingElse documentation comment...
* @param someParam description
*/
public void doSomethingElse(Object someParam) {
// ...implementation goes here...
}
}
点击中间区域
呼出菜单
上一章
目录
下一章
×