If we want to refactor an enum (contained in the domain layer) to a polymorphic class, using "simple" abstract methods could be a bad idea, if all the switch and if statements we want to refactor are inside the other layers (like the business or the presentation layer), because we could end up to reference these layers inside the domain layer:
public abstract class MyRefactoredEnum
{
public abstract void DoSomething(IBusinnessObject aBizObject); //dependency to the biz. layer
public abstract MvcHtmlString GetImgTag(); //dependency to presentation layer
}
(in the example above, we can have a "cross reference" problem too)
I've found that the visitor pattern ( http://en.wikipedia.org/wiki/Visitor_pattern ) it's a valid solution to this problem: in the domain layer we define only the MyRefactoredEnum.IVisitor interface, and all the other layers can implement their own visitors.
The only problem: when we modify the MyRefactoredEnum.IVisitor interface (for example, because we've added another MyRefactoredEnum's subclass) we have to modify and recompile all projects and solutions that reference the domain model. We can solve the problem using reflection ( http://surguy.net/articles/visitor-with-reflection.xml ), but it can be slow...
Is there a better pattern to refactor an enum?
PS: sorry for my awful English :)