oop - Solution to the lack of covariance with generics in c# 2.0 (BindingList) -
This is a design question I have a business object, and there are 5 business object types received from it.
I will have a class that is a binding list as a member. I will have 5 classes
Because sympathy does not work here, how would you design to reduce the code repetition? I can definitely check the binding list and I want to go with the datatelle, in which case the problem ends.
But since everyone knows about the bidding list, I love seeing how people will contact you.
Solution (based on the answer to Powell Minave):
public class samplebase {secure string m_seq; Secure string m_id; Safe string m_weight; Safe string m_units; Public Sample Base (String Seek, String ID, String Weight, String Unit) {Seak = CQ; Id = id; Weight = weight; Unit = units; } Public Samplebusiness () {} Public String Seq {get {return m_seq; } Set {m_seq = value; }} Public string id {get {return m_id; } Set {m_id = value; }} Public string weight {received {return m_weight; } Set {m_weight = value; }} Public string units {get {return m_units; } Set {m_units = value; }}} Public class FwdSample: samplebase {secure string m_std_id; Public FwdSample () {} Public FwdSample (String Seek, String ID, String Weight, String Units, String Std_id): Base (CEC, ID, Weight, Unit) {StdId = std_id; } Public string STDId {get {return m_std_id; } Set {m_std_id = value; }}} // The public essence class of finished classes runbase & lt; T & gt; Where T: samplebase, new () {secure binding list & lt; T & gt; M_samples; Public runbase () {} Add Public Zero (T Sample) {m_samples.Add (Sample); } Public Zune update (int index, T sample) {m_samples [index] = sample; } Public Zero deletion {m_samples.RemoveAt (index); } Public binding list & lt; T & gt; Samples {Back {m_samples; }}} Public Sector FwdRun: Runbase & lt; FwdSample & gt; {Public FwdRun () {m_samples = new binding list & lt; FwdSample & gt; (); }
Your bidding list
is considered private member ( Or protected), and otherwise you appear in your class API, then you might want something like this:
class base {// is not a compulsory list that does not need all the members They should be here ...} class base & lt; TDRid & gt; : Base where TDrive is done: Base & lt; TDRid & gt; {Binding List & Lieutenant; TDRid & gt; List = new binding list & lt; TDRid & gt; (); // All members who need the binding list should be here} Category Derived1: Base & lt; Derived1 & gt; {...} Category Derived2: Base & lt; Derived2 & gt; {...} ...
Comments
Post a Comment