由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 有谁读过Design Patterns Explained: A New Perspective on Obj (转载)
相关主题
[c++]distinct default parameter value in inherited class问两个算法题, 没什么头绪
design patterns到底有用吗?请教一个design的问题
求推荐讲OO Design的书prototype和abstract factory的区别
factory and abstract factory 的区别How many people use design patterns when coding?
王垠:解密“设计模式”Python:How to replace 2 different patterns in 1 line in file
大部份 design pattern 是不需要的快速系统学习 c++ design pattern有什么好书或者网站吗
请问Managed DirectX 画圆Questions about MAKEFILE
问一到算法题关于 VC++ vitual, reload 和 derive的一个问题...
相关话题的讨论汇总
话题: double话题: drawline话题: shape话题: y1话题: y2
进入Programming版参与讨论
1 (共1页)
t**********s
发帖数: 930
1
【 以下文字转载自 Java 讨论区 】
发信人: tennisalways (tennisforever), 信区: Java
标 题: 有谁读过Design Patterns Explained: A New Perspective on Object-Oriented Design?
发信站: BBS 未名空间站 (Wed May 30 20:40:43 2007)
觉得是本好书,但发现了几处我觉得是错误的地方。
谁能和我站内讨论?
谢谢
o******r
发帖数: 259
2
我读过
人家不是解读GOF的book嘛
哪错了,
我来翻翻

Oriented Design?

【在 t**********s 的大作中提到】
: 【 以下文字转载自 Java 讨论区 】
: 发信人: tennisalways (tennisforever), 信区: Java
: 标 题: 有谁读过Design Patterns Explained: A New Perspective on Object-Oriented Design?
: 发信站: BBS 未名空间站 (Wed May 30 20:40:43 2007)
: 觉得是本好书,但发现了几处我觉得是错误的地方。
: 谁能和我站内讨论?
: 谢谢

t**********s
发帖数: 930
3
179页,One Rule, One Place. 和181-182页的代码矛盾。
protected void drawLine 既出现在abstract public class Shape里,也出现在
public class Rectangle extends Shape里。
这是一处。

【在 o******r 的大作中提到】
: 我读过
: 人家不是解读GOF的book嘛
: 哪错了,
: 我来翻翻
:
: Oriented Design?

o******r
发帖数: 259
4
我的可能是老版,
这是你看到的code吗?
//Example 9-1 Java Code Fragments
class Rectangle {
public void draw () {
drawLine(_x1,_y1,_x2,_y1);
drawLine(_x2,_y1,_x2,_y2);
drawLine(_x2,_y2,_x1,_y2);
drawLine(_x1,_y2,_x1,_y1);
}
abstract protected void
drawLine ( double x1, double y1,
double x2, double y2);
}
class V1Rectangle extends Rectangle {
drawLine( double x1, double y1,
double x2, double y2) {
DP1.draw_a_line( x1,y1,x2,y2);
}
}
class V2Rectangle extends Rectangle {
drawLine( double x1, double y1,
double x2, do

【在 t**********s 的大作中提到】
: 179页,One Rule, One Place. 和181-182页的代码矛盾。
: protected void drawLine 既出现在abstract public class Shape里,也出现在
: public class Rectangle extends Shape里。
: 这是一处。

t**********s
发帖数: 930
5
这段code是没用bridge pattern 的code.
这只是简单的inheritance,生成了很多的subclass,作者反对这种code。
我说的有问题的code是相应的使用了bridge pattern 的code。
不知你的老版上能否找到。

【在 o******r 的大作中提到】
: 我的可能是老版,
: 这是你看到的code吗?
: //Example 9-1 Java Code Fragments
: class Rectangle {
: public void draw () {
: drawLine(_x1,_y1,_x2,_y1);
: drawLine(_x2,_y1,_x2,_y2);
: drawLine(_x2,_y2,_x1,_y2);
: drawLine(_x1,_y2,_x1,_y1);
: }

o******r
发帖数: 259
6
那就是这段了
要再不是就你自己贴code给大家看了
//Example 9-3 Java Code Fragments
class Client {
public static void main
(String argv[]) {
Shape r1, r2;
Drawing dp;
dp= new V1Drawing();
r1= new Rectangle(dp,1,1,2,2);
dp= new V2Drawing ();
r2= new Circle(dp,2,2,3);
r1.draw();
r2.draw();
}
}
abstract class Shape {
abstract public draw() ;
private Drawing _dp;
Shape (Drawing dp) {
_dp= dp;
}
public void drawLine (
double x1,double y1,
double x2,double y2) {
_dp.drawLine(x1,y1,x2,y2);
}
public void drawCircle (
double x,

【在 t**********s 的大作中提到】
: 这段code是没用bridge pattern 的code.
: 这只是简单的inheritance,生成了很多的subclass,作者反对这种code。
: 我说的有问题的code是相应的使用了bridge pattern 的code。
: 不知你的老版上能否找到。

k*****t
发帖数: 71
7
你列的部分code类似第二版我想要的说的,从中摘录如下:
我认为有问题的代码我在代码下标注。
第一版和第二版这段代码的区别是Shape, 几个public 变成protected了。
abstract class Shape {
abstract public draw() ;
protected Drawing myDrawing;
Shape (Drawing drawing) {
myDrawing= drawing;
}
protected void drawLine (
double x1,double y1,
double x2,double y2) {
myDrawing.drawLine(x1,y1,x2,y2);
}
protected void drawCircle (
double x,double y,double r) {
myDrawing.drawCircle(x,y,r);
}
}
class Rectangle extends Shape {
public Rectangle (
Drawing dp,
double x1,double y1,
dou

【在 o******r 的大作中提到】
: 那就是这段了
: 要再不是就你自己贴code给大家看了
: //Example 9-3 Java Code Fragments
: class Client {
: public static void main
: (String argv[]) {
: Shape r1, r2;
: Drawing dp;
: dp= new V1Drawing();
: r1= new Rectangle(dp,1,1,2,2);

o******r
发帖数: 259
8
你说的那个问题,老版里面没有
drawLine在基类Shape里面有完整定义,
在派生类Rectangle里面确实没有必要再写了,
而且是相同的code
难道作者的意思是“可以”在Rectangle里面实现不同的drawLine?
polymorphism

drawing

【在 k*****t 的大作中提到】
: 你列的部分code类似第二版我想要的说的,从中摘录如下:
: 我认为有问题的代码我在代码下标注。
: 第一版和第二版这段代码的区别是Shape, 几个public 变成protected了。
: abstract class Shape {
: abstract public draw() ;
: protected Drawing myDrawing;
: Shape (Drawing drawing) {
: myDrawing= drawing;
: }
: protected void drawLine (

t**********s
发帖数: 930
9
你注意到没有public class Circle extends Shape 里的drawCircle 也有问题。
Shape 里drawCircle已定义了。所以Circle class 里的draw应该是:
public void draw(){
drawCircle(_x,_y,_z)
}
你可以下载第二版看看。好书是好书,但不少错误。

【在 o******r 的大作中提到】
: 你说的那个问题,老版里面没有
: drawLine在基类Shape里面有完整定义,
: 在派生类Rectangle里面确实没有必要再写了,
: 而且是相同的code
: 难道作者的意思是“可以”在Rectangle里面实现不同的drawLine?
: polymorphism
:
: drawing

1 (共1页)
进入Programming版参与讨论
相关主题
关于 VC++ vitual, reload 和 derive的一个问题...王垠:解密“设计模式”
How to compile multiple c files into one obj file?大部份 design pattern 是不需要的
singleton question请问Managed DirectX 画圆
好一点的cross platform GUI library,除了QT,还有啥?问一到算法题
[c++]distinct default parameter value in inherited class问两个算法题, 没什么头绪
design patterns到底有用吗?请教一个design的问题
求推荐讲OO Design的书prototype和abstract factory的区别
factory and abstract factory 的区别How many people use design patterns when coding?
相关话题的讨论汇总
话题: double话题: drawline话题: shape话题: y1话题: y2