0Pricing
C# Academy · Lesson

Design (interfaces + inheritance)

Design a simple Shape API with an interface and a small base class; decide what belongs to the contract vs implementation detail.

Project overview

Goal: Define a tiny, clear contract for shapes.

  • Use an interface for behavior
  • Keep the surface minimal
  • Allow many shapes to plug in

Contract first

Create a small IShape contract with Area() and Perimeter(). Utilities can depend on the interface.

using System;

// Interface: minimal behavior all shapes must provide
public interface IShape
{
  double Area();
  double Perimeter();
}

// A tiny helper to print any IShape
public static class ShapePrinter
{
  public static void Print(IShape s)
  {
    Console.WriteLine("A=" + s.Area() + " P=" + s.Perimeter());
  }
}

public class Program
{
  public static void Main(string[] args)
  {
    // No concrete shapes yet; interface compiles and is ready.
    Console.WriteLine("Shape API ready");
  }
}

All lessons in this course

  1. Design (interfaces + inheritance)
  2. Implementation & tests
  3. Polymorphic behaviors
← Back to C# Academy