Note that there are some explanatory texts on larger screens.

plurals
  1. POC# class design with Generic structure
    primarykey
    data
    text
    <p>This might be a simple one, but my head is refusing to wrap around that, so an outside view is always useful in that case!</p> <p>I need to design an object hierarchy to implement a Parameter Registration for a patient. This will take place on a certain date and collect a number of different parameters about a patient (bloodpressure, heartrate etc). The values of those Parameter Registrations can be of different types, such as strings, integers, floats or even guids (for lookup lists).</p> <p>So we have:</p> <pre><code>public class ParameterRegistration { public DateTime RegistrationDate { get; set; } public IList&lt;ParameterRegistrationValue&gt; ParameterRegistrationValues { get; set; } } public class ParameterRegistrationValue { public Parameter Parameter { get; set; } public RegistrationValue RegistrationValue { get; set; } // this needs to accomodate the different possible types of registrations! } public class Parameter { // some general information about Parameters } public class RegistrationValue&lt;T&gt; { public RegistrationValue(T value) { Value = value; } public T Value { get; private set; } } </code></pre> <p><em><strong>UPDATE</em></strong>: Thanks to the suggestions, the model has now morphed to the following:</p> <pre><code>public class ParameterRegistration { public DateTime RegistrationDate { get; set; } public IList&lt;ParameterRegistrationValue&gt; ParameterRegistrationValues { get; set; } } public abstract class ParameterRegistrationValue() { public static ParameterRegistrationValue CreateParameterRegistrationValue(ParameterType type) { switch(type) { case ParameterType.Integer: return new ParameterRegistrationValue&lt;Int32&gt;(); case ParameterType.String: return new ParameterRegistrationValue&lt;String&gt;(); case ParameterType.Guid: return new ParameterRegistrationValue&lt;Guid&gt;(); default: throw new ArgumentOutOfRangeException("Invalid ParameterType: " + type); } } public Parameter Parameter { get; set; } } public class ParameterRegistrationValue&lt;T&gt; : ParameterRegistrationValue { public T RegistrationValue {get; set; } } public enum ParameterType { Integer, Guid, String } public class Parameter { public string ParameterName { get; set; } public ParameterType ParameterType { get; set;} } </code></pre> <p>which is indeed a bit simpler, but now I'm wondering, since the IList in ParameterRegistration points to the <em>abstract</em> ParameterRegistrationValue object, how will I be able to get the actual value out (since its stored on the sub-objects)?</p> <p>Maybe the whole generic thing is indeed not quite the way to go after all :s</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.
    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