Search Results

Search found 1 results on 1 pages for 'user2972231'.

Page 1/1 | 1 

  • Sad logic on types

    - by user2972231
    Code base is littered with code like this: BaseRecord record = // some BaseRecord switch(record.source()) { case FOO: return process((FooRecord)record); case BAR: return process((BarRecord)record); case QUUX: return process((QuuxRecord)record); . . // ~25 more cases . } and then private SomeClass process(BarRecord record) { } private SomeClass process(FooRecord record) { } private SomeClass process(QuuxRecord record) { } It makes me terribly sad. Then, every time a new class is derived from BaseRecord, we have to chase all over our code base updating these case statements and adding new process methods. This kind of logic is repeated everywhere, I think too many to add a method for each and override in the classes. How can I improve this?

    Read the article

1