类层次结构 [英] Class hierarchy

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

问题描述

我必须实现一个类层次结构。

基类是四边形类。

不同类型的梯形是梯形,平行四边形,矩形,正方形。


四边形

| _

梯形

| _

平行四边形

| _

矩形

| _

Square

四边形班级需要四个顶点的坐标。

我必须在其他类中实现什么?

在梯形中我插入什么?

谢谢。

I would have to implement a class hierarchy.
The base class is the class Quadrilateral.
The discendents arre th classes Trapezoid, Parallelogram, Rectangle, Square.

Quadrilateral
|_
Trapezoid
|_
Parallelogram
|_
Rectangle
|_
Square
The class Quadrilateral takes the cordinates of the four vertex.
What must I implement in the other classes?
In the trapezoid what do I insert?
Thanks.

推荐答案



" Piotre Ugrumov" < AU ************ @ tin.it>在消息中写道

新闻:%我******************** @ news4.tin.it ...


这是你的课程作业吗?


"Piotre Ugrumov" <au************@tin.it> wrote in message
news:%I********************@news4.tin.it...

is this your course homework?

我必须实现一个类层次结构。
基类是Quadrilateral类。 br />中世纪的梯形,平行四边形,矩形,
广场。
四边形
| _
梯形
| _
平行四边形 | _
矩形
| _
广场
Quadrilateral类占据了四个顶点的坐标。
我必须在其他类中实现什么?
在梯形中我插入什么?
谢谢。
I would have to implement a class hierarchy.
The base class is the class Quadrilateral.
The discendents arre th classes Trapezoid, Parallelogram, Rectangle, Square.
Quadrilateral
|_
Trapezoid
|_
Parallelogram
|_
Rectangle
|_
Square
The class Quadrilateral takes the cordinates of the four vertex.
What must I implement in the other classes?
In the trapezoid what do I insert?
Thanks.



Piotre Ugrumov写道:
Piotre Ugrumov wrote:
我必须实现一个类层次结构。
基类是四边形类。
上下文是梯形,平行四边形,矩形,正方形。

Quadrilate ral
| _
梯形
| _
平行四边形
| _
矩形
| _
广场
class Quadrilateral采用四个顶点的坐标。


这是否有实际的理由?一个正方形是一个

矩形的事实并不意味着类Square必须来自类

Rectangle。这种设计通常效率低下。原因是

派生类不需要基类提供的通用性。

。例如,你说Quadrilateral取了
四个顶点。如果这些顶点存储在成员变量中,那么通过从Quadrilateral派生Square来获得
,你强制Square记住所有

四个顶点。这些成员将被浪费在Square中,因为Square

可以由一个顶点和一个边长定义。

我必须在其他类中实现什么?
在梯形中我插入什么?
I would have to implement a class hierarchy.
The base class is the class Quadrilateral.
The discendents arre th classes Trapezoid, Parallelogram, Rectangle, Square.

Quadrilateral
|_
Trapezoid
|_
Parallelogram
|_
Rectangle
|_
Square
The class Quadrilateral takes the cordinates of the four vertex.
Is there a practical reason to do this? The fact that a square is a
rectangle does not mean that class Square must be derived from class
Rectangle. This sort of design is typically inefficient. The reason is
that the derived classes don''t need the generality that likely will be
provided by the base class. For example, you said Quadrilateral "takes"
four vertices. If those vertices are stored in member variables, then
by deriving Square from Quadrilateral, you force Square to remember all
four vertices. These members will be wasted in Square, since a Square
can be defined by one vertex and a side length.
What must I implement in the other classes?
In the trapezoid what do I insert?




为了做什么?您期望使用这些课程吗?


-Jeff



In order to do what? For what do you expect to use these classes?

-Jeff


" Piotre Ugrumov" < AU ************ @ tin.it>在消息中写道

news:%I ******************** @ news4.tin.it ...
"Piotre Ugrumov" <au************@tin.it> wrote in message
news:%I********************@news4.tin.it...
我必须实现一个类层次结构。
基类是四边形类。
对象是梯形,平行四边形,矩形,
方形。
四边形
| _
梯形
| _
平行四边形
| _
矩形
| _
广场
四边形采取四个顶点的坐标。
我必须在其他类中实现什么?
在梯形中我插入什么?
谢谢。
I would have to implement a class hierarchy.
The base class is the class Quadrilateral.
The discendents arre th classes Trapezoid, Parallelogram, Rectangle, Square.
Quadrilateral
|_
Trapezoid
|_
Parallelogram
|_
Rectangle
|_
Square
The class Quadrilateral takes the cordinates of the four vertex.
What must I implement in the other classes?
In the trapezoid what do I insert?
Thanks.



假设这是一个家庭作业问题(否则我会用

设计狡辩)我会说你可以用类来实现这个层次结构

,仅在构造函数方面有所不同。例如:


class Square:public Rectangle

{

public:

Square(double x0,双y0,双x1,双y1):

矩形(x0,y0,x1,y1,x0 + y1-y0,y0 + x1-x0){}

};


这里我假设一个Rectangle的构造函数需要三个点,

第四个可以从前三个计算出来。


-

Cy
http://home.rochester.rr.com/cyhome/


这篇关于类层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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