0

I have a task where I need to do a well-projected hierarchy for classes of different geometric figures:

  • circle
  • circumference
  • ring
  • rectangle
  • triangle
  • etc.

At first, I made an abstract class Figure as follows:

abstract class Figure
{
    public abstract double Area { get; }

    public abstract double GetArea();
}

I planned that every other class that describes a particular figure will be an inheritor of the Figure one. And the idea of the Area in the Figure works right before the moment when I understand that Circumference has no Area.

And I can't decide what to do next: describe another abstract class AbstractCircle, delete this Area property and method from the Figure or just set Area = 0 in the Circumference. Or maybe just make the Circumference to be an inheritor of the Circle and then set Area = 0?

Is it logically correct? I mean, would this logic be understandable for people who will read this program?

I will be glad to see the tips and comments.

Kate Orlova
  • 3,225
  • 5
  • 11
  • 35
Sidney Lee
  • 35
  • 6
  • This may help you : [What is polymorphism, what is it for, and how is it used?](https://stackoverflow.com/questions/1031273/what-is-polymorphism-what-is-it-for-and-how-is-it-used/58197730#58197730) –  Jun 20 '20 at 23:45
  • Since this sounds like homework, can you please post the exact text of the homework you've been asked to do? – Enigmativity Jun 21 '20 at 00:29
  • Circumference is not a figure, it is a property of circle so you should not consider that as one of the classes. Every has differ properties which you can use to calculate area. So area is a common property you can create in base class and other needed properties in specific child classes. – Chetan Jun 21 '20 at 03:02
  • Also: Each figure could/should have a property `Filled`. – TaW Jun 21 '20 at 07:17

1 Answers1

0

It sounds like you are on the right track. Let's take a look at the different geometric figures that you are trying to classify:

  • circle - (this is a shape)
  • circumference - (this is a property of a shape)
  • ring - (this is a shape)
  • rectangle - (this is a shape)
  • triangle - (this is a shape)

All of these are shapes except for the circumference. Like area, circumference is a property of a shape. Each two-dimensional shape can have a circumference, which will be implemented in a different way per shape. Thus, your Figure class should not need to be implemented by circumference. Rather, circumference should be a property of your abstract class:

abstract class Figure
{
    public abstract double Area { get; }    
    public abstract double GetArea();
    public abstract double Circumference { get; }
}

Now, all of your geometric shapes can implement this class without running into the difficulties that you were seeing.

Simona
  • 279
  • 1
  • 8