Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

Questions tagged [enum]

Enum (also enumeration) is a data type consisting of a set of named values called elements, members or enumerators of the type. The enumerator names are usually identifiers that behave as constants in the language, and are often predefined with an implied ordering.

Filter by
Sorted by
Tagged with
5 votes
1 answer
334 views

I see this pattern a lot, especially with countries, or more generally regions. An enum is defined with additional fields and with methods that translate to and from these values. Example: import ...
user2740's user avatar
  • 159
3 votes
3 answers
310 views

I am working on a C# project and I have a somewhat large number of labels (~100) that have some sort of relationships between one another. Here is a minimal dummy example that illustrates this: ...
evolved_antenna's user avatar
2 votes
1 answer
134 views

I will get to the question in a minute.... We have 2 in house services that either have an API contract between the 2 that involves an enum or the enum value is stored in a shared database. I don't ...
jdtommy's user avatar
  • 129
2 votes
1 answer
672 views

Although I love Rust's enums (and the idea of making illegal states unrepresentable), I'm struggling to represent (ironic, yes) them in databases like PostgreSQL when the variants have data associated ...
yoshke's user avatar
  • 29
0 votes
3 answers
8k views

I can write an enum with properties besides the name and ordinal. A very generic example would be: public enum ExampleEnum { EXAMPLE0(Example.example0), EXAMPLE1(Example.example1), ...
CPlus's user avatar
  • 1,219
5 votes
6 answers
4k views

Over the years I've many times seen folks enumerate error codes for exceptions in Java. I generally have felt this leads to more tedious code and does not provide value. For example, there will be an ...
Kirby's user avatar
  • 271
2 votes
1 answer
865 views

In the simplest case, I have some code where the user may want to do one thing (a), another thing, (b), or both (a+b). The options are reasonably complex and have their own functions, but I would like ...
QuantumChris's user avatar
3 votes
2 answers
409 views

I have seen in mainly high level languages, but also in lower level languages, the use of option names as strings to specify one of several fixed options, or as flags, or more generally, code using ...
CPlus's user avatar
  • 1,219
0 votes
3 answers
3k views

I have built a string to enum converter, which converts a known set of strings that it receives into enum, in order to satisfy a function pointer. Some of you may recognize some elements of this ...
HFOrangefish's user avatar
2 votes
1 answer
4k views

I have a class that I use to define different types of plots I am performing class MyPlots(Enum): STANDARDSCALE = "standard" LOGSCALE = "log" there are default values ...
La Cartuccia's user avatar
2 votes
3 answers
1k views

I have seen a common design pattern where there will be a "lookup table" in the database like this: Color ColorId ColorName 1 Blue 2 Red 3 Green with a foreign key constraint on other tables,...
JoelFan's user avatar
  • 7,151
-4 votes
1 answer
170 views

I'm currently reading Code Complete by Steve McConnell. In section 12.6, Enumerated Types, he says that we can define first and last entries like limits: Define the first and last entries of an ...
CoderDesu's user avatar
  • 1,015
1 vote
2 answers
1k views

I am practicing design patterns and OO concepts such as inheritance in java and I'm writing an application that represents a vending machine. I have two questions focused on ideal structure and design ...
Bob Jones's user avatar
6 votes
3 answers
7k views

This question considers whether SQL DB data should be represented as an enum or by a reference table, when the application code is aware of particular instances of said data. I'll illustrate with an ...
Moeghoeg's user avatar
3 votes
4 answers
2k views

The project I'm working on has a code dependency on a TeamNames enum. The problem with this is that the project needs to be recompiled and redeployed on any addition/deletion in TeamNames. How can I ...
NiceOne's user avatar
  • 33
2 votes
5 answers
1k views

I have an enum that works very well to represents date periods and the number of months in those date periods: public enum StandardDatePeriod { ONE_MONTH(1), SIX_MONTH(6), ONE_YEAR(12), ...
James's user avatar
  • 285
1 vote
4 answers
906 views

I am working on low level design of cab booking type of system and feeling stuck at modelling Vehicle in Booking class.I came up with following design. Class Vehicle { } ...
stkUser's user avatar
  • 81
2 votes
3 answers
712 views

I am reading about OOD and came across Parking lot design problem.Parking lot has parking floors which has parking spots.The parking spot class looks as follow: public enum ParkingSpotType { ...
rahul sharma's user avatar
3 votes
0 answers
726 views

Currently, in my PowerShell scripts I am using [ValidateSet()] in my functions in order to limit the options for user input. Now I discovered the Enum as an alternative. I have read a couple of blogs ...
Alex_P's user avatar
  • 171
4 votes
2 answers
7k views

I have a string variable named status in my code that can take on three values "Starting", "In-progress", and "Complete". A friend of mine said it was good practice to enforce that status has one of ...
user35734's user avatar
  • 159
0 votes
1 answer
665 views

I have been using a pattern in a lot of places (mainly C#) that I would like to know the name of. Here is an example of it in C#: public enum ThingType { A, B, C } public interface ...
Romen's user avatar
  • 111
2 votes
1 answer
2k views

Currently an enum in our project takes properties in the constructor. They are practically guaranteed to be entirely different across every different enum. Now I'd like to add an property which is a ...
Joe's user avatar
  • 405
10 votes
2 answers
2k views

I've been writing some code comments, and I've been trying to refer to the index integer of a enum type, but I'm not sure what it's called. I'm tempted to call it the identifier, however there is ...
DubDub's user avatar
  • 645
1 vote
3 answers
1k views

A Quick Note I know the question title is a little odd but I haven't had much caffeine this morning so I'm having trouble thinking clearly right now. If you have any suggestions for a better title, ...
Taco's user avatar
  • 1,175
2 votes
3 answers
405 views

I have a general organization problem with my code. I'm modeling DNA, and I've created a Nucleobase struct to store the "letter" of the DNA. For ease of use, I would prefer the following functionality ...
Adam B's user avatar
  • 1,660
1 vote
2 answers
86 views

I have these tables: contacts, tags, contact_tags. (contact_tags has columns contact_id and tag_id.) Administrators can manually create new tags via an internal website. Administrators can also ...
Ryan's user avatar
  • 167
2 votes
2 answers
1k views

I'm considering refactoring some Java code that passes around objects that implement the interface Map<String, Object>. The strings are all (as far as I know) from some fixed list of string ...
Ryan1729's user avatar
  • 234
4 votes
3 answers
778 views

I was looking into the Enum design recommended by Microsoft (see here), and I found a statement that made me stop to think for a while: X DO NOT use an enum for open sets (such as the operating ...
curiousguy_08's user avatar
0 votes
5 answers
665 views

Background: I have seem some argument for using enumeration classes instead of enum in C#, in particular, this section from a book available at MSDN. On the references there is this "Enums are ...
user1620696's user avatar
  • 4,967
1 vote
1 answer
350 views

As I am maintaining and extend a software system in Java, I saw a colleague (who left due to retirement) implementing a table with a generic approach. This approach is unluckily bound to tables (ui-...
J-P's user avatar
  • 37
3 votes
3 answers
1k views

I have been going back and forth in a discussion about polymorphic enums to call different DAO methods depending on enum entry, and I haven't been able to get a common agreement on this subject. Lets ...
Danilo Silva's user avatar
1 vote
4 answers
1k views

Backstory (You can skip) I am writing a pronunciation library for irregular words. Take something like the following: T1E1s // tee one E one es | tee one E ones 1994-1995// 1994 (minus|dash|to|) ...
Anon's user avatar
  • 3,649
1 vote
0 answers
155 views

Is there a software pattern (or some recommended guidelines) for how to convert between enum values and discriminated unions? Or more specifically: project a discriminated union onto its enum case? ...
Michael's user avatar
  • 299
1 vote
3 answers
1k views

A coworker of mine insists that this is the right way to write enums in C# public enum ExampleEnum { InvalidItem, Item1, Item2, Item3, MaxItem } We have enums defined like this ...
chanban's user avatar
  • 121
1 vote
1 answer
385 views

In the C++, there are 6 bitwise operators: Symbol Operator & bitwise AND | bitwise inclusive OR ^ bitwise XOR (eXclusive OR) << left shift >> right shift ~...
Anon's user avatar
  • 3,649
1 vote
1 answer
340 views

I will use the reference tables for the first time so I have some questions about it. Example Table ------------------------ id | description | ------------------------ 1 | Some description1 |...
mnesimi's user avatar
  • 21
2 votes
2 answers
220 views

I was reading on this SESE page about using a variable to indicate the object type, more specifically, an enum. The accepted answer states: When your weapon types enum just mirrors the class ...
user avatar
7 votes
4 answers
4k views

We started a project recently, and during the design process, we have some arguments among team members. We have to deal with enumerations so we ended up with three choices. Have the enumerations as ...
pik4's user avatar
  • 385
-1 votes
1 answer
250 views

I came across this Enum and Struct declarations in a project supposedly done by an expert. The declarations / definitions are little different than what im used to so far. enum EnumKeys { KEY_MENU ,...
ABCD's user avatar
  • 117
1 vote
1 answer
360 views

I've seen several questions on this website explaining that enums should be kept in the database when there is one (this one for example). However, I feel like my case is different and there are extra ...
ZamenWolk's user avatar
0 votes
1 answer
1k views

I have a program where the domain is focused around programs. As part of the domain, I have a 'ProgramType', which is an enum formed mostly via a string from the database but also via a bit of logic. ...
Sarov's user avatar
  • 403
4 votes
1 answer
10k views

Over many years, I always find myself reconsidering this design, so I wanted to get some feedback on my solution to it. Problem: I need a limited amount of objects = instances from a class, and I ...
Aganju's user avatar
  • 1,473
1 vote
1 answer
187 views

I have recently started working on a project where we have a workflow engine which has flexibility to add dynamic states and corresponding actions for each state and all these are stored in database. ...
digi's user avatar
  • 111
4 votes
1 answer
4k views

I am storing information about Widgets in my database, and each Widget has one (non-unique) transformation function associated with it. My problem is how to associate Widgets with their transformation ...
Plasma's user avatar
  • 151
1 vote
1 answer
1k views

I have a table UserItems {ID, UserID, ItemID} Items must be in RAM (not in db table). What is better for this? As enum with attributes or as dictionary of items?: enum Items { [InternalParam("...
Glebka's user avatar
  • 141
4 votes
3 answers
190 views

I am developing a bot which I need to start and stop at will. I have 2 buttons in my form, StartButton and StopButton which change the state. The Bot has 4 possible states: starting, started, ...
Joao Vitor's user avatar
21 votes
9 answers
86k views

If you have an enum with values only (no methods as one could do in Java), and this enum is part of the business definition of the system, should one write unit tests for it? I was thinking that they ...
IS1_SO's user avatar
  • 347
11 votes
7 answers
1k views

I'm developing a new service in a micro-services environment. This is a REST service. For simplicity, let's say that the path is: /historyBooks And the POST method for this path creates a new history ...
Ron Klein's user avatar
  • 761
1 vote
1 answer
2k views

I have an Enum in Python that looks something like this: import enum class Color(enum.Enum): red = 'red' blue = 'blue' yellow = 'yellow' puce = 'puce' chartreuse = 'chartreuse' ...
Wayne Werner's user avatar
  • 2,390
1 vote
3 answers
7k views

I'm Working with php and we using enum's by create an Abstract class that mocking enum behavior - but my question is cross-languages. Where all the helper functions like toString, getEnumTypes, ...
Michael's user avatar
  • 197