I am writing a class library to model a car. I have a base class called “Dimension”, which provides the properties/methods for measurements of the cars (Eg length, width, etc). This is for the entire car in general.
However, I need to provide dimensions on individual parts too (E.g. wheels). Wheels, for example, only use a subset of the information. Eg the width, and not every readily available property. Does it make sense to use the same base class for this or do I need to look into something more sophisticated to model this accurately?
Thanks
A Car has Dimension; a Car is not a subclass of Dimension.
By making Car inherit from Dimension you are squandering the only available inheritance slot available to you in C#.
There is little benefit to be had from using inheritance to share properties amongst concrete subclasses, especially now that C# has things like automatic properties to save typing. Better to save your inheritance slot for some future requirement.
I would suggest instead giving the Car object properties to define the dimensions as appropriate, and perhaps have it (and Wheel) implement an interface, say IDimension, to allow you to treat Car and Wheel polymorphically if you want to write code that can be applied to any objects that have dimensions: