Hacker News new | ask | show | jobs
by tjtrapp 3183 days ago
iirc the last time i used a switch was to create a static factory method to instantiate objects. the static class had a static method that took an enum as input. the return type was an abstract base class. the method switched off of the enum, new'd up the type - did some common initialization - and returned the new object to the caller. this approach keeps your "creation" logic in one place.