Enum vs Lookup table vs Enum reflection vs State pattern

You should not sprinkle your code with this check everywhere

if (application.Status == Status.New)
{ //do something }
else if (application.Status == Status.Closed)
{ //do other things }

Instead, use the state pattern. Change the state whenever the mode of the application changes and forward all your calls to the state's methods. You'll have a much cleaner and easier to maintain code.

As for changing the status, that has got nothing do with the state pattern. So you can use whichever approach is elegant.


I'd create a Status class that contains the differences, and call those. So (in Python):

class StatusZero(object):
    def call_me(self, app):
       print 'Hello, from ' + app.name
       return db.prepare_specific_status_zero_request()


class StatusOne(object):
    def call_me(self, app):
        print 'Hi, from ' + app.name
        return db.prepare_specific_status_one_request()

states = { 'status_zero' : StatusZero(), 'status_one' : StatusOne() }

class Application(object):
    name = 'My App'
    status = states['status_zero']

    def change_state(self, state):
        status = state

    def call_me(self):
        state_key = self.status.call_me(self)
        self.change_state(states[state_key])

Fast, easy to keep the functionality compartmentalized, and with a reasonable inheritance pattern between the states you can share the functions which don't differ.