K

Update:I think you should be reasoned. Objection Teacher.The fact is that inheritance is not a means of reuse of the code, especially not a means of presenting One To the top, and to add two others as a characteristic. There's a way to express that the target is a private case of the predator. Reason-- https://ru.wikipedia.org/wiki/%D0%9F%D1%80%D0%B8%D0%BD%D1%86%D0%B8%D0%BF_%D0%BF%D0%BE%D0%B4%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B8_%D0%91%D0%B0%D1%80%D0%B1%D0%B0%D1%80%D1%8B_%D0%9B%D0%B8%D1%81%D0%BA%D0%BE%D0%B2 ♪In your case, the triangle. not Private location. In particular, No. be used in a reasonable way, for example, instead of a point representing top Triangle. The top of the triangle is three points, but not three triangles.In contrast, for presentthe right succession always makes sense. For example, since selmon Yes fish, if they send you to fish, and you bring the salmon, you'll do the right thing.Of course, it is only technically possible to inherit any object from anyone. But... opportunitythe language provided does not mean that you have the right to use it in terms of objective-oriented design.If the teacher insists, think about alternative sources of knowledge.You shouldn't want that. Triangle not I don't think so.The way it's done now is right.If there's a general functionality, it's better to put it in the general. Interface♪ It's possible we can still make a common class alert. GeometricObject♪It is difficult for me to understand that there is a “transfer” in terms of assignment. In my opinion, the code must look like,public interface IMovable
{
void Move(double dx, double dy);
Point Center { get; }
void RotateAbout(Point p, double alpha)
}
public static class MovableExtensions
{
public static void MoveRight(this IMovable self, double d) //сдвиг вправо
{
self.Move(+d, 0);
}
public static void MoveLeft(this IMovable self, double d) //сдвиг влево
{
self.Move(-d, 0);
}
public static void MoveUp(this IMovable self, double d) //сдвиг вверх
{
self.Move(0, +d);
}
public static void MoveDown(this IMovable self, double d) //сдвиг вниз
{
self.Move(0, -d);
}
public static void RotateAboutCenter(this IMovable self, double alpha)
{
self.RotateAbout(self.Center, alpha);
}
}
public class Point : IMovable
{
public double X { get; private set; }
public double Y { get; private set; }
public Point(double _x, double _y)
{
X = _x;
Y = _y;
}
public void Move(double dx, double dy)
{
X += dx;
Y += dy;
}
public Point Center { get { return this.Clone(); } }
public void RotateAbout(Point p, double alpha)
{
double distanceToRotationCenter = GeoTools.Distance(this, p);
double dx = distanceToRotationCenter * Math.Cos(d);
double dy = -distanceToRotationCenter * Math.Sin(d);
X += dx;
y += dy;
}
internal Point Clone() { return new Point(X, Y); }
}
public static class GeoTools
{
public static double Distance(Point p1, Point p2)
{
double dx = p2.X - p1.X;
double dy = p2.Y - p1.Y;
return Math.Sqrt(dx * dx + dy * dy);
}
}
public class Triangle : IMovable
{
private Point a, b, c;
public Point A { get { return a.Clone(); } }
public Point B { get { return b.Clone(); } }
public Point C { get { return c.Clone(); } }
public Triangle(Point _a, Point _b, Point _c)
{
a = _a.Clone();
b = _b.Clone();
c = _c.Clone();
}
public void Move(double dx, double dy)
{
a.Move(dx, dy);
b.Move(dx, dy);
c.Move(dx, dy);
}
public Point Center
{
get
{
return new Point((a.X + b.X + c.X) / 3.0, (a.Y + b.Y + c.Y) / 3.0);
}
}
public void RotateAbout(Point p, double alpha)
{
a.RotateAbout(p, alpha);
b.RotateAbout(p, alpha);
c.RotateAbout(p, alpha);
}
}