Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For extensible Field reading:</p> <p>Make Field an abstract class, and make all your common methods abstract as well. Classes derived from Field will specify exactly what those methods do. </p> <p>You can then pass objects of these derived classes back to methods that accept a Field, and they can call the methods of Field without needing to worry about the real class that is being used. Interface would be even better, but you don't get code reuse for common functionality.</p> <p>For extensible Field creating:</p> <p>You will always have to do a switch or something somewhere at the boundaries of your program to determine which class to create. Your goal is to do this in only one place. Your design - determining the factory method to use based on data in the DB - is ideal. </p> <p>Look into making a class that will have the responsibility to create Field objects based on DB data and just pass it around. If it were abstract, you could subclass it and pass it as a parameter to methods, methods that will get the data they want by calling something like fieldFactory.GetNewField(myParameter);.</p> <p>For extensible serialization:</p> <p>Research DataContractResolver.</p> <p>Tips:</p> <p>If you find yourself having to switch on the type of Field in more than one place (where the constructors are called), you're doing it wrong. An example of this is your process(field) method. Instead, Field or IField should have an abstract Process method. Consumers will just call Field.Process and not care how it is implemented.</p> <p>Example:</p> <pre><code>public abstract class Field { public abstract void Process(); } public class ExtendedField : Field { public override void Process() { /*Extended Field Specific Stuff Here*/ } } //consumer code public void DoStuffWithABunchOfFieldsOfUnknownType(IEnumerable&lt;Field&gt; fields) { foreach (Field field in fields) { field.Process(); } } </code></pre>
 

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