I hate to say that it depends, but it depends.
If you need to simulate every single car in the world, and you have methods that you can call on them (for example, "change the tire", this is a process that is very different for each model), then yes, you are going to have many bloated classes , because your real situation in the world is also bloated.
If you just want to have a database with images of archetypal cars, and you are not a car, be it a photo of your neighboring copy or your sister’s copy, you can reset the bottom layer. "2009 VW CC" may well be an instance, although you can visualize that it is also a class in another model.
Alternatively, you may not need to make it a true subclass at all. A simple reference may be enough. For example, an insurance company knows about a large list of car models and years, but developers do not write one subclass for each. Instead, they have a database of car models where one line can represent the 2009 VW CC. When you insure your car, they create a copy of the "Insured Car" with reference to a copy of "VW CC 2009".
This strictly does not follow “Use inheritance for the is-a relationship,” but the operations for all types of cars are identical - these are only changes (for example, the insurance price per year) that change, and new car models are recorded in the database, not in code.
It is assumed that you can simulate the differences between difference models as just parameters for the same methods on the car.
(Beyond this: when the iPhone became available through the telephone company’s websites, I noticed that it broke its class models — their websites seemed to handle dozens of phone brands and models on one page — presumably using a simple phone database and their functions, and then you need a special page to process iPhone models, apparently because their classes required new special methods to support some aspects of selling iPhone. Automated trading tables said: “Press 1 to buy a phone n. Press 2 to buy an iPhone. ")
Oddthinking
source share