Does the strategy pattern incur more overhead than a switch statement?
up vote
0
down vote
favorite
I have a switch statement that currently handles around 20 different numerical event types. The event ID ranges from 1000-5000. The switch
statement is becoming more difficult to maintain and read.
My idea is to put each event type into its own class and then store it into an EnumMap
. This approach will make the code maintainable and easier to read but what am I really sacrificing here?
Each client (ranging from 1000-5000 clients) that connects will have its own initialization of this EnumMap
along with the all the event type classes. This is a lot of overhead, is it not?
In regards to performance, is there any downside to using an EnumMap
over a switch
? Does javac
compile them similarly? There will be times where every millisecond counts.
java switch-statement javac strategy-pattern enum-map
add a comment |
up vote
0
down vote
favorite
I have a switch statement that currently handles around 20 different numerical event types. The event ID ranges from 1000-5000. The switch
statement is becoming more difficult to maintain and read.
My idea is to put each event type into its own class and then store it into an EnumMap
. This approach will make the code maintainable and easier to read but what am I really sacrificing here?
Each client (ranging from 1000-5000 clients) that connects will have its own initialization of this EnumMap
along with the all the event type classes. This is a lot of overhead, is it not?
In regards to performance, is there any downside to using an EnumMap
over a switch
? Does javac
compile them similarly? There will be times where every millisecond counts.
java switch-statement javac strategy-pattern enum-map
2
"Each client (ranging from 1000-5000 clients) that connects will have its own initialization of this EnumMap along with the all the event type classes" Why? Can't you have a single shared copy and pass the client-specific information (this
or whatever) to the implementations stored in the map?
– T.J. Crowder
Nov 18 at 15:00
@T.J.Crowder Yes I could. Making theEnumMap
static is something I was considering as well and I suppose that addresses my overhead questions.
– user0000001
Nov 19 at 15:26
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a switch statement that currently handles around 20 different numerical event types. The event ID ranges from 1000-5000. The switch
statement is becoming more difficult to maintain and read.
My idea is to put each event type into its own class and then store it into an EnumMap
. This approach will make the code maintainable and easier to read but what am I really sacrificing here?
Each client (ranging from 1000-5000 clients) that connects will have its own initialization of this EnumMap
along with the all the event type classes. This is a lot of overhead, is it not?
In regards to performance, is there any downside to using an EnumMap
over a switch
? Does javac
compile them similarly? There will be times where every millisecond counts.
java switch-statement javac strategy-pattern enum-map
I have a switch statement that currently handles around 20 different numerical event types. The event ID ranges from 1000-5000. The switch
statement is becoming more difficult to maintain and read.
My idea is to put each event type into its own class and then store it into an EnumMap
. This approach will make the code maintainable and easier to read but what am I really sacrificing here?
Each client (ranging from 1000-5000 clients) that connects will have its own initialization of this EnumMap
along with the all the event type classes. This is a lot of overhead, is it not?
In regards to performance, is there any downside to using an EnumMap
over a switch
? Does javac
compile them similarly? There will be times where every millisecond counts.
java switch-statement javac strategy-pattern enum-map
java switch-statement javac strategy-pattern enum-map
asked Nov 18 at 14:56
user0000001
7922623
7922623
2
"Each client (ranging from 1000-5000 clients) that connects will have its own initialization of this EnumMap along with the all the event type classes" Why? Can't you have a single shared copy and pass the client-specific information (this
or whatever) to the implementations stored in the map?
– T.J. Crowder
Nov 18 at 15:00
@T.J.Crowder Yes I could. Making theEnumMap
static is something I was considering as well and I suppose that addresses my overhead questions.
– user0000001
Nov 19 at 15:26
add a comment |
2
"Each client (ranging from 1000-5000 clients) that connects will have its own initialization of this EnumMap along with the all the event type classes" Why? Can't you have a single shared copy and pass the client-specific information (this
or whatever) to the implementations stored in the map?
– T.J. Crowder
Nov 18 at 15:00
@T.J.Crowder Yes I could. Making theEnumMap
static is something I was considering as well and I suppose that addresses my overhead questions.
– user0000001
Nov 19 at 15:26
2
2
"Each client (ranging from 1000-5000 clients) that connects will have its own initialization of this EnumMap along with the all the event type classes" Why? Can't you have a single shared copy and pass the client-specific information (
this
or whatever) to the implementations stored in the map?– T.J. Crowder
Nov 18 at 15:00
"Each client (ranging from 1000-5000 clients) that connects will have its own initialization of this EnumMap along with the all the event type classes" Why? Can't you have a single shared copy and pass the client-specific information (
this
or whatever) to the implementations stored in the map?– T.J. Crowder
Nov 18 at 15:00
@T.J.Crowder Yes I could. Making the
EnumMap
static is something I was considering as well and I suppose that addresses my overhead questions.– user0000001
Nov 19 at 15:26
@T.J.Crowder Yes I could. Making the
EnumMap
static is something I was considering as well and I suppose that addresses my overhead questions.– user0000001
Nov 19 at 15:26
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53362222%2fdoes-the-strategy-pattern-incur-more-overhead-than-a-switch-statement%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
"Each client (ranging from 1000-5000 clients) that connects will have its own initialization of this EnumMap along with the all the event type classes" Why? Can't you have a single shared copy and pass the client-specific information (
this
or whatever) to the implementations stored in the map?– T.J. Crowder
Nov 18 at 15:00
@T.J.Crowder Yes I could. Making the
EnumMap
static is something I was considering as well and I suppose that addresses my overhead questions.– user0000001
Nov 19 at 15:26