Skip to main content

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
335 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
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
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
2 votes
1 answer
867 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
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
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
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
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
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
3 votes
0 answers
727 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
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
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
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
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
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
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
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
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
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
-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
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
1 vote
1 answer
189 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
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
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
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