Specific answers are difficult because they really depend on the particulars of your problem space, but in general you would use subclasses of Car
if all kinds of Car
shared some functionality. E.g.:
public class Car {
public void Start() { }
}
And then you could have different types of Car
:
public class Sedan : Car {
public void OpenAllFourDoors() { }
}
public class Coupe : Car {
public void OpenAllTwoDoors() { }
}
You don't generally need to put the class hierarchy into its own namespace, there are other sets of guidance for namespace definitions. Typically, expect namespaces to take the form of something like CompanyName.ProductName.ModuleName or something similar.
Later, when you need an array (or, more commonly, a collection) of cars, you would create a collection of Car
. When you grab a reference from this collection, though, you won't be able to OpenAllFourDoors
or OpenAllTwoDoors
because you won't know which subclass of Car
you're working with.
(Apologies for C#-centric syntax)