Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should try to use a configuration class and pass an instance of that to the factory. The configuration classes would build a hierarchy, where a special configuration class would exist for each result you expect from the factory. Each configuration class captures the specific properties of the factory result.</p> <p>For the example you've given I'd write a BasicLabelConfiguration and a CustomLabelConfiguration derived from it. The BasicLabelConfiguration captures the tracking reference, while the CustomLabelConfiguration captures the custom text.</p> <p>Finally the factory makes a decision based on the type of the passed configuration object.</p> <hr> <p>Here's an example of the code:</p> <pre><code>public class BasicLabelConfiguration { public BasicLabelConfiguration() { } public string TrackingReference { get; set; } } public class CustomLabelConfiguration : BasicLabelConfiguration { public CustomLabelConfiguration() { } public string CustomText { get; set; } } public class LabelFactory { public ILabel CreateLabel(BasicLabelConfiguration configuration) { // Possibly make decision from configuration CustomLabelConfiguration clc = configuration as CustomLabelConfiguration; if (clc != null) { return new CustomLabel(clc.TrackingReference, clc.CustomText); } else { return new BasicLabel(configuration.TrackingReference); } } } </code></pre> <p>Finally you'd use the factory like this:</p> <pre><code>// Create basic label ILabel label = factory.CreateLabel(new BasicLabelConfiguration { TrackingReference = "the reference" }); </code></pre> <p>or</p> <pre><code>// Create basic label ILabel label = factory.CreateLabel(new CustomLabelConfiguration { TrackingReference = "the reference", CustomText = "The custom text" }); </code></pre>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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