Define the capability in an interface and keep rectangle validation in the implementation. Example: public interface IShape { decimal Area { get; } } public sealed record Rectangle : IShape { public Rectangle(decimal width, decimal height) { if (width <= 0 || height <= 0) throw new ArgumentOutOfRangeException(); Width = width; Height = height; } public decimal Width { get; } public decimal Height { get; } public decimal Area => Width * Height; } IShape shape = new Rectangle(5m, 3m); Console.WriteLine(shape.Area); // 15 The interface lets consumers work with different shapes without knowing concrete types.
Backbencher Developer · · 0 likes