Note that there are some explanatory texts on larger screens.

plurals
  1. POIs the Visitor pattern the best way to refactor domain enums to classes?
    primarykey
    data
    text
    <p>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:</p> <pre><code>public abstract class MyRefactoredEnum { public abstract void DoSomething(IBusinnessObject aBizObject); //dependency to the biz. layer public abstract MvcHtmlString GetImgTag(); //dependency to presentation layer } </code></pre> <p>(in the example above, we can have a "cross reference" problem too)</p> <p>I've found that the visitor pattern ( <a href="http://en.wikipedia.org/wiki/Visitor_pattern" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Visitor_pattern</a> ) 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.</p> <p>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 ( <a href="http://surguy.net/articles/visitor-with-reflection.xml" rel="nofollow noreferrer">http://surguy.net/articles/visitor-with-reflection.xml</a> ), but it can be slow...</p> <p>Is there a better pattern to refactor an enum? </p> <p>PS: sorry for my awful English :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload