Skip to main content
Software Engineering

Questions tagged [switch-statement]

The tag has no summary.

Filter by
Sorted by
Tagged with
2 votes
3 answers
920 views

Should I still "replace conditional with polymorphism" if the condition is from dynamic load data?

I know there are already some questions about replacing if else with polymorphism, for example: Applying Replace Conditional with Composition in functional programming Is it wrong to use any type of ...
0 votes
1 answer
82 views

Avoiding repeating code when assigning pointer addresses based on branch

I have the following code in C that reads data off a char array and makes decisions on what variables should some pointers point to. char preset1[20]; char preset1Name[20]; int preset1Temp; int ...
3 votes
2 answers
835 views

How to use visitor pattern when objects change frequently

It is said that visitor pattern is applicable to problems where objects rarely change but we add actions on those objects more frequently. What if the objects are changing too though? For example we ...
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 ...
28 votes
7 answers
7k views

How does this switch statement do "multiple things"?

This doubt is about Switch Statements from Chapter 3: Functions of the book named Clean Code Here we have a function: public Money calculatePay(Employee e) throws InvalidEmployeeType { switch (e....
2 votes
2 answers
1k views

Large method with nested switch case(s) refactoring (Java)

Essentially I've got a bunch of formulas in two giant methods in a class designed to do math transformations and evaluations to multiple inputs. Where the inputs are actually lists of inputs (as there ...
0 votes
1 answer
639 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 ...
11 votes
5 answers
4k views

Looking for an effective pattern to cope with switch statements in C#

I sometimes end up with services encapsulating the responsibility of doing some sort of business process for which there are several possible outputs. Typically one of those output is success and the ...
5 votes
4 answers
34k views

Throw an exception in default case of a switch?

In my class I have a processor manager that contains a switch case. I have just changed the real name values to Ant, Parrot and Snake. switch (name) { case "ant": return new ...
7 votes
6 answers
12k views

Is there a way to speed up a big switch statement?

As a practice I'm working on a CPU simulator (runs at about 1.78MHz) and I'm using a switch statement to execute correct opcodes based on the value in the IR (instruction register) variable. This ...
2 votes
2 answers
513 views

Why does C# type pattern matching use a different variable scoping behavior than traditional switch blocks?

Traditional switch blocks have one scope, so the following throws a compiler error "A local variable or function named 'message' is already defined in this scope": switch(value) { case 1: ...
1 vote
4 answers
995 views

How would I add up enumerator values such that any combination provides a unique number?

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|) ...
47 votes
12 answers
21k views

Avoiding the goto voodoo?

I have a switch structure that has several cases to handle. The switch operates over an enum which poses the issue of duplicate code through combined values: // All possible combinations of One - ...
Taco's user avatar
  • 1,175
-1 votes
2 answers
1k views

How to get switch case values [closed]

I was wondering if there is a way to get the values of every case in a switch statement? When you provide a not implemented case, I would like to throw some exception and provide a list of available ...
9 votes
2 answers
276 views

fall-through switch for executing a sequence of steps

My program needs to execute a sequence of steps from start to end. But based on different input the start point will vary, e.g, some will run from the first step to end, some will run from the 2nd ...

15 30 50 per page
1
2 3 4

AltStyle によって変換されたページ (->オリジナル) /