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.
134 questions
5
votes
1
answer
335
views
What do you call an enum that translates its own values?
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 ...
2
votes
1
answer
134
views
Node Services and Enum Sharing
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 ...
0
votes
3
answers
8k
views
Getting an enum value by a unique property in Java
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),
...
2
votes
1
answer
867
views
Elegant way to handle two options, when both is also an option
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 ...
0
votes
3
answers
3k
views
Optimizing a string to enum converter [closed]
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 ...
2
votes
3
answers
1k
views
Enforce correspondence between enum and lookup table
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,...
1
vote
2
answers
1k
views
Concept/Design question: Alternatives to switch/conditional statements and Enums
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 ...
3
votes
4
answers
2k
views
Alternative to using enum
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 ...
1
vote
4
answers
906
views
Using Enum to represent VehicleType in cab Booking system
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
{
}
...
3
votes
0
answers
727
views
Enum versus ValidateSet
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 ...
0
votes
1
answer
665
views
Name of this enum-based design pattern to get the type
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 ...
10
votes
2
answers
2k
views
What is the name for the integer part of a enum?
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 ...
2
votes
3
answers
405
views
How to model a Struct with a limited set of values that behaves like an enum?
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 ...
2
votes
2
answers
1k
views
How to gradually refactor a Map with string keys to use enum keys?
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 ...
0
votes
5
answers
665
views
What if there is specific logic for one particular value of an enumeration class?
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 ...
3
votes
3
answers
1k
views
Is Enum Polymorphism bad for DAO Methods?
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 ...
1
vote
0
answers
155
views
Convert between enum and discriminated union
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? ...
1
vote
1
answer
385
views
How to understand and design functions with enumeration arguments that work in tandem with bitwise operators in C++ and Qt?
In the C++, there are 6 bitwise operators:
Symbol Operator
& bitwise AND
| bitwise inclusive OR
^ bitwise XOR (eXclusive OR)
<< left shift
>> right shift
~...
2
votes
2
answers
220
views
Using a Collection with Attributes to Check and Make Decisions
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 ...
-1
votes
1
answer
250
views
Few unusual C/C++ declarations
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 ,...
0
votes
1
answer
1k
views
Enum as part of domain - enum + extension or consolidate into one class?
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. ...
1
vote
1
answer
189
views
What is the solution of enum based dynamic states and actions used in a project
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.
...
1
vote
1
answer
1k
views
Enum or dictionary for inmemory parameter
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("...
21
votes
9
answers
86k
views
Should one test the values of an enum using unit tests?
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 ...
1
vote
1
answer
2k
views
What's the most idiomatic way to make a collection of enum.Enum in Python?
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'
...