课堂设计问题 [英] class design question

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

问题描述

这是我前一段时间采访过的,我想知道

正确答案。设置是这样的;


如果我有一个基类食物还有两个类别肉。和veg

继承食物,因此;


食物

/ \

/ \

肉类蔬菜

我还有一个基类人类,所有人都吃,所以有一种方法

吃因此定义(*表示方法吃)

人类* ----无效(吃饭和食物)

/ \

/ \\ \\ b
素食食肉动物


现在的问题是我们如何处理这样的事情,以便vegaterian将b / b
从不吃肉,我们班级设计的条款等等。可能会有一两百万美元的答案但是我想从这个组的

专家那里得到最好的一个。

非常感谢周末愉快。


GrahamO

This came up in an interview I did a while ago and I wanted to know
the correct answer. The setup is this;

If I have a base class "food" and also two classes "meat" and "veg"
that inherit from food, thus;

food
/ \
/ \
meat veg
Also I have a base class human, and all humans eat so there''s a method
eat defined thus (* denotes the method eat)
human *----void (eat& food)
/ \
/ \
vegetarian carnivore

Now the question is how do we work things such that a vegaterian will
never eat meat, in terms of our class design etc. There''s probably a
million and one answers but I''d like to get the best one from the
experts on this group
thanks much and have a nice weekend.

GrahamO

推荐答案

* grahamo:
* grahamo:

如果我有一个基类食物还有两个类别肉。和veg
从食物中继承而来;

食物
/ \
/ \
肉类蔬菜
<另外我还有一个基类人类,所有人都吃,所以有一种方法因此定义吃(*表示方法吃)

人类* ----无效(吃饭和吃饭)
/ \
/ \\ /
素食食肉动物

现在的问题是我们如何处理这样的事情,一个vegaterian将
从不吃肉,就我们的班级设计等而言。可能有一百万个和一个答案,但我想从这个组的
专家那里得到最好的一个

If I have a base class "food" and also two classes "meat" and "veg"
that inherit from food, thus;

food
/ \
/ \
meat veg

Also I have a base class human, and all humans eat so there''s a method
eat defined thus (* denotes the method eat)

human *----void (eat& food)
/ \
/ \
vegetarian carnivore

Now the question is how do we work things such that a vegaterian will
never eat meat, in terms of our class design etc. There''s probably a
million and one answers but I''d like to get the best one from the
experts on this group




没有最佳答案。


如果你想让素食者吐出任何肉,我建议你检查了素食主义者对'吃'的动态食物类型。


如果你想要素食从不提供首先把肉作为食物,

我建议你删除一般的''吃'功能,或者让它不公开。


- -

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

问:为什么这么糟糕?

答:热门发布。

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



There is no best answer.

If you want a vegetarian to spit out any meat it''s served, I suggest you check
the dynamic type of food in the vegetarian''s override of ''eat''.

If you want a vegetarian to never be offered meat as food in the first place,
I suggest you remove the general ''eat'' function, or make it non-public.

--
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?


这里给出的类层次结构违反Liskov替换

原则。原则规定:


在类层次结构中,应该可以处理专门的

对象

,就像它是一个基类对象。


以下文章详细描述了这一点:
http://www.eventhelix.com/RealtimeMa..._principle.htm


Deepa

-

EventStudio 2.5 - http:// www .EventHelix.com / EventStudio

以纯文本格式输入模型;以PDF / Word格式生成序列图

The class hierarchies presented here violates the Liskov Substitution
Principle. The principle states:

In class hierarchies, it should be possible to treat a specialized
object
as if it were a base class object.

The following article describes this in detail:
http://www.eventhelix.com/RealtimeMa..._principle.htm

Deepa
--
EventStudio 2.5 - http://www.EventHelix.com/EventStudio
Enter model in plain text;generate sequence diagram in PDF/Word


* EventHelix.com:
* EventHelix.com:

此处提供的类层次结构违反了Liskov Substitution
原则。

The class hierarchies presented here violates the Liskov Substitution
Principle.




其实没有。很多都没有具体说明。有一些更严格的

规格你会违反LSP,而其他则没有。


-

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

问:为什么这么糟糕?

A:热门帖子。

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



Actually no. Much is left unspecified. With some sets of more rigorous
specifications you get LSP violations, with others not.

--
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?


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

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