maps of classes of enums
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Seasons' Greetings to all,
I'm building a class to generate reports. The report's format will be different based on which state requests the report.
To this end my class has several enums which define the structure of the output line for a specific state.
I'd like to have a mapping between stateCodes and their associated enums. Then the report-writing method accepts a stateCode and a row of data, uses the statecode to lookup which enum to use, apply that enum's formatting to the row of data, and return a string.
Here's a really stripped-down version:
As usual, any ideas, suggestiong, pointers, examples and positive criticism are always welcome!
TIA,
Still-learning Steve
I'm building a class to generate reports. The report's format will be different based on which state requests the report.
To this end my class has several enums which define the structure of the output line for a specific state.
I'd like to have a mapping between stateCodes and their associated enums. Then the report-writing method accepts a stateCode and a row of data, uses the statecode to lookup which enum to use, apply that enum's formatting to the row of data, and return a string.
Here's a really stripped-down version:
As usual, any ideas, suggestiong, pointers, examples and positive criticism are always welcome!
TIA,
Still-learning Steve
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I don't understand why those classes are enums. Why not just provide an abstract class and have each state override it appropriately?
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The fact that your Layout_AZ and Layout_TX are exactly the same except for two integer values suggests that there is something not quite right about this approach. Also, unless you're designing framework, resorting to reflection is usually a huge clue that one is looking at a problem the wrong way.
You don't need enums. You need an abstract Layout class that has concrete implementations for AZ and TX.
You don't need enums. You need an abstract Layout class that has concrete implementations for AZ and TX.
dennis deems
Ranch Hand
Posts: 808
Stuart Rogers
Ranch Hand
Posts: 141
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
thanks for your suggestions! I got a little further with my approach with
but will try it your way as well. I went with enums because they are inherently static.
Thanks again for your replies!
Happy New Year,
Still-learning Steve
but will try it your way as well. I went with enums because they are inherently static.
Thanks again for your replies!
Happy New Year,
Still-learning Steve
posted 13 years ago
That really isn't a good reason for choosing enums. And looking for something which is static isn't usually a good idea, either.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Stuart Rogers wrote:I went with enums because they are inherently static.
That really isn't a good reason for choosing enums. And looking for something which is static isn't usually a good idea, either.
Stuart Rogers
Ranch Hand
Posts: 141
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
and besides, no matter how you slice it, something's going to have map the state being used to the associated enum/ extended class
Stuart Rogers
Ranch Hand
Posts: 141
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
ok, I got a little further
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
What now? You need some methods to override. Let me suggest "formatStateCode" and "formatDistrictCode" to start with? Of course I'm just guessing because your original code didn't actually do anything.
Also let me suggest this for your startup code, to reduce the need for reflection elsewhere in your code:
Also let me suggest this for your startup code, to reduce the need for reflection elsewhere in your code:
Stuart Rogers
Ranch Hand
Posts: 141
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
ah, clever. I'll tinker with this new approach over the next few days.
Thanks and Happy New Year!
Still-learning Steve
Thanks and Happy New Year!
Still-learning Steve
Stuart Rogers
Ranch Hand
Posts: 141
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I hacked at this a bit more, stripped out all the enum stuff, to come up with
This looks syntactically correct but doesn't give me what I want:
In Eclipse I can get as far as RptXXX.Layoutt.lookupByState("AZ"). but it can't see Layoutt_AZ's buildOutputRecord method., probably because the map sets its objects to Layoutt and loses further class data
Any more suggestions/ideas/hints/examples out there to finish this off?
TIA,
Still-learning Steve
This looks syntactically correct but doesn't give me what I want:
In Eclipse I can get as far as RptXXX.Layoutt.lookupByState("AZ"). but it can't see Layoutt_AZ's buildOutputRecord method., probably because the map sets its objects to Layoutt and loses further class data
Any more suggestions/ideas/hints/examples out there to finish this off?
TIA,
Still-learning Steve
Stuart Rogers
Ranch Hand
Posts: 141
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
here's the piece I was missing
I can test it once I've got some data in my tables to run the reports against. Will post my results.
Thanks to all,
Still-learning Steve
I can test it once I've got some data in my tables to run the reports against. Will post my results.
Thanks to all,
Still-learning Steve
Stuart Rogers
Ranch Hand
Posts: 141
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
This works great:
so now in my application I can call forth:
Nice!
Thanks to all who responded!
CASE CLOSED
Still-learning Steve
so now in my application I can call forth:
Nice!
Thanks to all who responded!
CASE CLOSED
Still-learning Steve
| Men call me Jim. Women look past me to this tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |








