课堂设计问题。 [英] Class design question.

查看:85
本文介绍了课堂设计问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这类设计是否设计不佳?


类矩形

{

双倍宽度,高度;

public:

double get_width()const {return width; }

double get_height()const {return height; }


void set_width(double width){this-> width = width; }

void set_height(double height){this-> height = height; }

};


如果是,那么为什么?

Is this class evidence of poor design?

class Rectangle
{
double width, height;
public:
double get_width() const { return width; }
double get_height() const { return height; }

void set_width(double width) { this->width = width; }
void set_height(double height) { this->height = height; }
};

If so then why?

推荐答案

* Jason Heyes:
* Jason Heyes:
这类设计是否设计不好?

类矩形
{
双倍宽度,高度;
公开:
double get_width()const {返回宽度; }
double get_height()const {return height; }

void set_width(double width){this-> width = width; }
void set_height(double height){this-> height = height; }
};


是的。


如果是,那么为什么?
Is this class evidence of poor design?

class Rectangle
{
double width, height;
public:
double get_width() const { return width; }
double get_height() const { return height; }

void set_width(double width) { this->width = width; }
void set_height(double height) { this->height = height; }
};
Yes.

If so then why?




没有用户定义constructor =>构造后的未定义状态。


和它一样(它与构造函数不同)没办法

同时分配宽度和高度。


还有证据表明编码不好,即使用不一致的

''this->'';即使在C ++中使用它通常也是糟糕的风格,但是

使用它不一致,就像消除歧义一样,更糟糕。


-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:Top-发布。

问:usenet和电子邮件中最烦人的事情是什么?



No user defined constructor => undefined state after construction.

And as it stands (it would be different with a constructor) no way
to assign both width and height at the same time.

Also there is evidence of poor coding, namely inconsistent use of
''this->''; even using it at all in C++ is generally poor style, but
using it inconsistently, just as a disambiguator, is worse.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


" Jason Heyes" < JA ******** @ optusnet.com.au>在消息中写道

news:41 ********************** @ news.optusnet.com.au ...
"Jason Heyes" <ja********@optusnet.com.au> wrote in message
news:41**********************@news.optusnet.com.au ...
这类是不良设计的证据吗?

类矩形
{width double,height;
public:
double get_width( )const {返回宽度; }
double get_height()const {return height; }

void set_width(double width){this-> width = width; }
void set_height(double height){this-> height = height; }
};

如果是,那么为什么?
Is this class evidence of poor design?

class Rectangle
{
double width, height;
public:
double get_width() const { return width; }
double get_height() const { return height; }

void set_width(double width) { this->width = width; }
void set_height(double height) { this->height = height; }
};

If so then why?




如果没有要执行的类不变量,并且没有理由

预计将来必须添加此功能,我将考虑使用普通结构:

struct Rectangle {

//考虑添加构造函数...

双倍宽度,高度;

};

-
< a rel =nofollowhref =http://ivan.vecerina.com/contact/?subject=NG_POSTtarget =_ blank> http://ivan.vecerina.com/contact/?subject=NG_POST < - 电子邮件联系表格



If there are no class invariants to enforce, and no reason
to expect having to add this capability in the future, I
would consider using a plain struct instead:
struct Rectangle {
//consider adding a constructor...
double width, height;
};
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form


" Jason Heyes"写道:
"Jason Heyes" writes:
这类设计是否设计不佳?

类矩形
{
双倍宽度,高度;
public:
double get_width()const {return width; }
double get_height()const {return height; }

void set_width(double width){this-> width = width; }
void set_height(double height){this-> height = height; }
};

如果是,那么为什么?
Is this class evidence of poor design?

class Rectangle
{
double width, height;
public:
double get_width() const { return width; }
double get_height() const { return height; }

void set_width(double width) { this->width = width; }
void set_height(double height) { this->height = height; }
};

If so then why?




是的,这是糟糕的设计。这只是一种混淆的方式,用一个简单的结构来完成可能是b
。复杂性应该有一些奖励,

这里没有奖励。



Yes, it''s poor design. It is just an obfuscated way of doing what could be
done with a simple struct. There should be some reward for complexity,
there are no rewards here.


这篇关于课堂设计问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆