Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat are the differences between the Builder, Factory Method, and Abstract Factory patterns?
    text
    copied!<p>A program receives a list of Messages (base type). Each message in the list has to be processed according to it's type (descendant type). However, different messages need different inputs in order to be processed correctly.</p> <p>What is the following technique called? (I haven't checked this code in a compiler)</p> <pre><code>abstract class MessageProcessor { public static MessageProcessor GetProcessor(Message message, DataDomain data) { if (message.GetType() == typeof(FooMessage)) { return new FooMessageProcessor(message, data.Name, data.Classification); } else if (message.GetType() == typeof(BarMessage)) { return new BarMessageProcessor(message, data.AccountNo, data.CreditLimit); } else throw new SomeException("Unrecognized type"); } public abstract void Process(); } </code></pre> <p>And this one?</p> <pre><code>static class MessageProcessorFactory { public static MessageProcessor GetProcessor(Message message, DataDomain data) { if (message.GetType() == typeof(FooMessage)) { return new FooMessageProcessor(message, data.Name, data.Classification); } else if (message.GetType() == typeof(BarMessage)) { return new BarMessageProcessor(message, data.AccountNo, data.CreditLimit); } else throw new SomeException("Unrecognized type"); } } </code></pre> <p>And what is it called if I can inject the ProcessBuilder class into a MessageProcessor (using a property or Setter) and then call Process?</p> <p>What technique would be the best pattern for solving this problem?</p>
 

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