Boolean vs. Enum to enter "New or used"

I have, perhaps, a stupid question ... I am trying to determine what is best for entering a property whose value will be either "new" or "used". Am I using enum , or should I just go with boolean (e.g. IsNew)? If I go with enum , what should I call this type and property name? (public NewOrUsed NewOrUsed {get; set;} <- confusing)

Obviously, with enum I can have a state that does not declare a value (NONE, NEW, USED), and enum more reliable (although it can be argued that there are no other values). Again, what is the appropriate name for this type and property?

With boolean - it's pretty straight forward (using IsNew or IsUsed)

I know this is stupid, but I'm curious what others think.

Relations Z ..

Update

If you prefer enum , comment on what the corresponding name should be for the type and property (for example, public NewUsedType NewOrUsed {get; set;} )

+4
source share
7 answers

You mentioned in the comment "I already have a condition - this refers to the state when something is Y" Used "(for example, the used car / book can be" honest "," like new "," mint "" condition); ) "

So, with this information, I would definitely go with bool . You already have an extensible way to establish state, so this is more categorical. You may want some time in the future, you might want something if more than one condition is considered β€œnew”, say:

 public enum ConditionType {Fair, LikeNew, Mint, New} public ConditionType Condition { get; set; } public bool IsNew { get { return Condition == ConditionType.New || Condition == ConditionType.Mint; } } 
+3
source

enum - a more secure future

Not really. You have no idea what the future will bring. If you need to change it later, change it. So, KISS . Go with:

  public bool IsNew { get; set; } 

Boom done. Move on, add value to another place.

+7
source

Use an enumeration. I would call it Condition . You do not need a value of None . You can just make it null.

+4
source

For the new, I would use a boolean; listing in this case would be superfluous.

+2
source

I would go with an enumeration if I were constantly translating a boolean value to the value "new" or "used".

If I were more interested in this value as an indicator (for example, do if(something.isNew) ), I would use a boolean value.

+2
source

eBay has New and New Other to distinguish between products sold in the original packaging and products sold in different packaging or without packaging. I would like to list its extensibility, what you called "future proof."

+1
source

I am generally against excessive engineering, so my first instinct used a logical one.

But conceptually, this does not look like a logical logical value. This is similar to an enumeration that currently has two values. Usually I consider conditions as new and used , and not as new and not new in my head.

I expect another Condition to be added at a later point in time, for example refurbished . But, of course, refactoring from a single object will not be so difficult thanks to IDE features such as Find All References . And you will have to retouch the logic using this property as soon as you add new values ​​to the enumeration.

Future protection is a less important reason for me. What he does not consider conceptually pure is more important than IMO.

+1
source

All Articles