Replace conditional with polymorphism – nice in theory but not practical

You’re right – “the conditionals are getting pushed up to the top of the chain” – but there’s no “just” about it. It’s very powerful. As @thkala says, you just make the choice once; from there on out, the object knows how to go about its business. The approach you describe – BaseAction, ViewAction, and the rest – is a good way to go about it. Try it out and see how much cleaner your code becomes.

When you’ve got one factory method that takes a string like “View” and returns an Action, and you call that, you have isolated your conditionality. That’s great. And you can’t properly appreciate the power ’til you’ve tried it – so give it a shot!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)