Using top down style is harder to comprehend code so look at it from old school.
using System;
using Calculators;
using CommercialRegistration;
using ConsumerVehicleRegistration;
using LiveryRegistration;
namespace ConsumerVehicleRegistration
{
partial class Program
{
static void Main(string[] args)
{
var tollCalc = new TollCalculator();
Car car = new ();
Console.WriteLine(tollCalc.CalculateToll(car));
Console.ReadLine();
}
}
}
namespace Calculators
{
public class TollCalculator
{
public decimal CalculateToll(object vehicle) =>
vehicle switch
{
Car c => 2.00m,
Taxi t => 3.50m,
Bus b => 5.00m,
DeliveryTruck t => 10.00m,
{ } => throw new ArgumentException(message: "Not a known vehicle type", paramName: nameof(vehicle)),
_ => throw new ArgumentNullException(nameof(vehicle))
};
}
}
namespace ConsumerVehicleRegistration
{
public class Car
{
public int Passengers { get; set; }
}
}
namespace CommercialRegistration
{
public class DeliveryTruck
{
public int GrossWeightClass { get; set; }
}
}
namespace LiveryRegistration
{
public class Taxi
{
public int Fares { get; set; }
}
public class Bus
{
public int Capacity { get; set; }
public int Riders { get; set; }
}
}