I have multiple kinds of an object, say Car for example.
Do I have each kind in an inherited class/subclass of Car?
Do I place these under a cartype namespace so as not to mess up the main namespace?
Then later when I need an array of cars, should I declare it as var currentCars():Car or var currentCars():Object? Would the former support any subclass of Car?
Specific answers are difficult because they really depend on the particulars of your problem space, but in general you would use subclasses of
Carif all kinds ofCarshared some functionality. E.g.:And then you could have different types of
Car: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 toOpenAllFourDoorsorOpenAllTwoDoorsbecause you won’t know which subclass ofCaryou’re working with.(Apologies for C#-centric syntax)