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.

learn more… | top users | synonyms

1
vote
3answers
222 views

Would combining enums with static strings in java be sloppy?

Currently my team has a number of constants defined as static final strings. I want to be able to iterate over these strings as if they were an enum in one location, but everywhere else they are used ...
4
votes
3answers
245 views

Is enum order sensitivity an antipattern?

Is it an anti-pattern to depend on a particular order of an enum's instance declarations? For example, consider: public enum CompassPoint { North, East, South, West; } These points ...
0
votes
0answers
82 views

Class to manage EEProm Memory for microcontroller in .netMF

I've got a working driver to access the EEPROM chip, but looking for much better management and access of the memory. I've been racking my brain about what's the best or correct approach to do this. ...
1
vote
2answers
146 views

One Enum vs Multiple Enums

I am developing an application where a user submits a mission and other users accept the mission. Pretty simple. I want to keep a track of the mission progress status and store it into a database. ...
4
votes
5answers
571 views

Is it okay to go against all-caps naming for enums to make their String representation simpler?

Several times I've seen people use title-case or even all lower-case naming for enum constants, for example: enum Color { red, yellow, green; } This makes working with their string form ...
1
vote
1answer
144 views

Java partial enum backed by the database

I have following problem: need to use enum in my java code, since I'll have to ask in my business logic things like if(someting == enumname.VALUE_ENUM){... but I don't have all the enum types at the ...
2
votes
1answer
189 views

Static properties and implicit “self” property in structures and enumerations vs classes in Swift

I am currently reading the Swift language documentation and came across these sentences in the chapter about methods: Similarly, type methods on structures and enumerations can access static ...
16
votes
5answers
3k views

Do enums create brittle interfaces?

Consider the example below. Any change to the ColorChoice enum affects all IWindowColor subclasses. Do enums tend to cause brittle interfaces? Is there something better than an enum to allow for ...
4
votes
2answers
238 views

Enums in java switch-statements and completeness

I feel like I should be able to find an answer to this, but it turns out to be harder to search than expected... so: In C#, when we do something like: enum MyEnumClass { A, B }; static String ...
4
votes
2answers
683 views

How can I avoid these nested repetitive ifs?

I'm trying to implement a web interface for a user database. Hosts can create guests for their courses, the guests can get deleted after the course has ended but have to remain in the database for a ...
1
vote
0answers
110 views

Should I use enums or arrays for a dynamic data source?

I've inherited an iOS project that uses NS_Enum to store the number of rows and sections in a UITableView At the moment, the UITableView is static; no rows are being added to it. However, that is what ...
1
vote
0answers
62 views

Enforce coding decision to include or exclude an Enum element in an EnumSet at compile time

I would like to enforce that the elements of a Java Enum are chosen or excluded from an EnumSet at compile time i.e. I am forced to make the decision to put it in the set or not whenever I create a ...
1
vote
1answer
163 views

Open closed principle vs abstraction leaking (Java enums)

In Java, an enum is not a plain replacement for a number (like in C/C++), but a family of objects which can have properties. For instance public enum Order { NAME("Ordering by name"), ...
4
votes
2answers
470 views

Is it a good practice to burn business logic into Enums?

Let's have a simplified business logic like this: public enum BusinessLogic { STAGE_ONE(true, false, false), STAGE_TWO(true, true, false), STAGE_THREE(false, false, true); private final ...
0
votes
1answer
141 views

Enum as singleton or fully functional class [duplicate]

Joshua Bloch claims that "a single-element enumeration type is the best way to implement a singleton" Why? I totally disagree with this statement because enumeration is data type with some ...
1
vote
3answers
129 views

Nullable enumeration values vs. “NoValue” or “Undefined”, etc

I often write code which translates entities in the database to domain objects. These entities often have fields which are constrained and translate to enumerations in the domain objects. In some ...
2
votes
1answer
186 views

Why use a enum to create the singleton pattern [duplicate]

Why would you use an enum to create a singleton pattern? To what purpose would it serve over a conventional singleton pattern? I have seen the above used. The code uses an enum to create this pattern ...
5
votes
2answers
474 views

Is it better to use strings or int to reference enums outside the java part of the system?

We were having a discussion at my work about the use of enums in Java. A coworker was arguing that when using enums on the server-side, whenever required we should use string to reference to it (for ...
1
vote
2answers
111 views

Enumerated types and their interpretation by compilers

It seems to me that a lot, if not most, compilers treat enumerated types as int underneath. In C/gcc, enums are compiled to int. In C#/Visual C#, you can change the underlying data type with something ...
3
votes
6answers
789 views

Explicitly define enum values, even if the default value is the same?

There are times when an enum's values are important: it is not necessary for them to be unique, they also need to have specific values. In such cases, should the values be explicitly defined, even if ...
1
vote
3answers
337 views

How can I mock this architecture?

This is not a very general question, so it may not exactly be appropriate here, but I could sure use a suggestion if you have one: I have an object containing a dictionary keyed off of an enum, ...
-1
votes
2answers
440 views

Is enum not a class? [closed]

I was just exploring enums. One thought came in my mind- what if a class can extend enum. I understand this is not practical, but what surprises me, is the compiler error given- "The type MyEnum ...
0
votes
2answers
134 views

Is there a way for Object 1 to call Object 2's enums in a function call?

For example, if I have two classes "Director" and "Follower". I want the Director to tell the follower where to go (ex: follower1.go(direction.LEFT)), and I want the Director to know what directions ...
3
votes
2answers
1k views

Best approach for multilingual Java Enum

I'm running into issues with an approach I am taking and am now wondering if I just started down the wrong path and should rethink my approach. Here is what I attempting. I would like to use an Enum ...
2
votes
1answer
385 views

Several enum classes that declare constants with the same names

I'm working on a Java library for sorts for Magic: the Gathering. Well, without going into a lot of detail, in the game there are five different colors of magic: white, blue, black, red, and green. ...
6
votes
7answers
1k views

Why isn't there a next operation on enums?

In most popular programming languages like Java and C# there is a way to define enums, which are essentially datatypes with a fixed set of values, e.g. DayOfWeek. The problem is, given a value, e.g. ...
0
votes
2answers
2k views

In what situation do Entity Framework enums become useful?

I am working on a project where there will be plenty of static options being stored in the database. I looked at using Enums for this, but do not see how they could be useful. They do not create any ...
2
votes
2answers
201 views

Allowing enum to express a valid combination of values

Suppose in a manufacturing environment, there are certain stock materials available for use in a product. For example, there are only a few different sizes of copper tube, each having a specific ...
1
vote
5answers
890 views

How to unit test a missing case in a switch statement where all cases are true

I often use enum types in my code with a switch to apply logic to each type. In these cases it's important that each enum has code implemented. For example; public enum eERROR { REQUIRED, ...
1
vote
1answer
546 views

constants/enums in API

What are a few ways constants and enums are dealt with when creating an API Client? I'm writing a client in python for our API and I've hit a sticking point with this. We use a lot of mappings to ...
2
votes
2answers
389 views

Are the IETF BCP 47 language tags defined as enums anywhere in JDK?

Are the IETF BCP 47 language tags defined as enums anywhere in JDK? For Locale.forLanguageTag() we pass values like fr-FR, jp-JP etc. Are there any enums already provided by JDK for it? Or should ...
2
votes
1answer
441 views

Which is better to use? (Enum or Constant)

I have my enum like this. enum Size{PAGE_SIZE=20, HEADER_SIZE=30 }; I only use them as constants(No enum variable created) in my program. i.e= int x = PAGE_SIZE + 20; So what is the ...
8
votes
3answers
1k views

How to represent (enum) types in a public API

I am working on a simple API that I want to use for my own client, and to open to the public in the future. I have "Item" objects which can have different "types". The type is a C "typedef enum", for ...
3
votes
3answers
2k views

Compatibility of Enum Vs. string constants

I was recently told that using Enum: public enum TaskEndState { Error, Completed, Running } may have compatibility/serialization issues, and thus sometimes it's better to use const string: public ...
3
votes
1answer
1k views

Could someone explain HaXe enums?

I have AS3/PHP background and some basic understaning of enums from C++. Saying shortly: I read this: http://haxe.org/ref/enums http://haxe.org/doc/cross/more_on_enum And though - good ...
5
votes
5answers
2k views

In what situations does it make sense to use an enumeration when writing object-oriented code?

Enumerations1 are often associated with procedural code rather than object-oriented code. They tend to give rise to similar switch statements scattered through the code, and in general, these are ...
1
vote
3answers
299 views

Does an in-code enumeration provide a stronger domain model than a static table?

Does an in-code enumeration provide a stronger domain model than a static database table? As an example, say I have an Marble entity, with a Color attribute. The color attribute has a finite set of ...
0
votes
1answer
271 views

use of Enum with flags in practice?

I just have read some stuff on enum today. Use of flags with enum was something interesting and new for me. But often practice and theoretical uses are different. I go through many articles they ...
8
votes
2answers
483 views

Why is Flags Enumeration considered an intermediate skill?

I was reading this article: Designing Flags Enumerations @ msdn and it says Combining flags enumeration values is an intermediate skill that should not be required for developers implementing ...
27
votes
4answers
16k views

Using scoped enums for bit flags in C++

An enum X : int (C#) or enum class X : int (C++11) is a type that has a hidden inner field of int that can hold any value. In addition, a number of predefined constants of X are defined on the enum. ...
6
votes
2answers
3k views

Nested Enum type in C++ or C#?

I've come across a recurring issue in a few of my recent projects in which I find myself using enums to represent state, or type, or something else, and I need to check against a few conditions. Some ...
4
votes
2answers
2k views

Is it possible to avoid enormously big switch in that case? [duplicate]

I'm writing a simple chess-related code with intention to write it clearly (performance doesn't matter at all). And this method I have doesn't look clean to me at all: public static Piece ...
4
votes
2answers
419 views

Do I really want a dynamic Enum, or something else? Better caching? A Struct?

This question is asked on SO and this site often it looks like. "How do I do a dynamic enum?" Answers range from you shouldn't to possible compile time solutions. Now my question is do I want a ...
12
votes
3answers
3k views

What are the downsides of implementing a singleton with Java's enum?

Traditionally, a singleton is usually implemented as public class Foo1 { private static final Foo1 INSTANCE = new Foo1(); public static Foo1 getInstance(){ return INSTANCE; } private ...
9
votes
7answers
4k views

Is it a bad practice to include all the enums in one file and use it in multiple classes?

I'm an aspiring game developer, I work on occasional indie games, and for a while I've been doing something which seemed like a bad practice at first, but I really want to get an answer from some ...
7
votes
4answers
2k views

Keeping an enum and a table in sync

I'm making a program that will post data to a database, and I've run into a pattern that I'm sure is familiar: A short table of most-likely (very strongly likely) fixed values that serve as an enum. ...
3
votes
3answers
1k views

How to deal with almost the same enums?

I need to define enums in several classes. The majority of fields are the same in all of the enums. But one has one or two more fields, another has fewer fields. Now I wonder what is the best way to ...
5
votes
4answers
3k views

Should I create an Enum mapping to my database table

I have a database table containing a list of systems relevant to the tool I am building, mostly in-house applications, or third-party systems we receive data from. This table is added to infrequently, ...
2
votes
2answers
741 views

Is switch-case over enumeration bad practice?

I have an enumeration with the commands Play, Stop and Pause for a media player. In two classes I do a switch-case over the received commands. The player runs in a different thread and I deliver the ...
5
votes
2answers
6k views

Best practice for packing Java enums?

What is the best practice for packaging Java enums? is it separate file for each enum? or having same file for all the enums? What are the pros and cons ?