C# Design – Is It OK to Have a Class with Only Boolean Properties?

asp.netcdatabase-designdesign

Scenario
We have a class Vehicle, this class contains some properties to define the object such as a CarBrand, TransmissionType, Color, etc..

A car (vehicle) also has options, these days a lot of options.
My idea is to create a separate class called Options and list the needed options that I require as a Boolean value, then use true or false to determine if the vehicle has that option or not.

Would this be considered a good idea or a lazy idea?
Should I even bother making a separate class for this or should I simply put all this info in the vehicle class.
Not just from a design point of view but also looking at the database to store this information.
There is no intention of making the vehicle class a base class for multiple other classes.

My alternative would simply be an array of string value's.
This would be less restrictive when it come to adding in new options and maybe even better in terms of data usage in a database (I think).

  • Booleans: every option will need a true or a false value.
  • Strings: there will be something or there will be nothing at all to store.

Ideas besides the 2 that I posted are also welcome.

Best Answer

Yes absolutely it is a good idea because we want the compiler to check as much as possible. If the options were a list of strings any mistypings would not be discovered until runtime.

The test you can do to see which fits your solutions is this: If you were to introduce a new option tomorrow is it acceptable to deploy a new version with new code or do you expect to make the change via configuration.

If the former there is no downside to using a bunch of boolean properties.