Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerics, Polymorphism, Interfaces: what is the solution?
    primarykey
    data
    text
    <p>I know the title is Very wide - spanning over a lot !</p> <p>And I hope that this question might evolve to a bigger "info wiki thingy" on the subjects.</p> <p><strong>What I have learned - so far:</strong></p> <ul> <li>When using Generics - understand the concepts (<a href="http://tech.turbu-rpg.com/149/generics-and-the-covariance-problem" rel="nofollow noreferrer">covariance and contravariance</a>).</li> <li><a href="https://stackoverflow.com/a/9142020/696574">Do NOT "mis-use"</a> the concept of generics combined with inheritance. I did and it could make you head directly into covariance problems! Make sure you "break off" the generic at the correct point in you inheritance - if you are combining the two.</li> </ul> <p><em>(please correct me - if you think i'm wrong, missing or have misunderstood anything).</em></p> <p><strong>My problem was:</strong></p> <p>But by now I've spend countless hours, trying to figure out, how to solve this "big puzzle" I have on my desk. And I've gotten some good answers from several of you SO users already - but now its time to get something working in a bigger scale.</p> <p>I ventured into Generics with this one: <a href="https://stackoverflow.com/a/7872779/696574">Generics and Polymorphism working together</a></p> <p>And now I'm kinda stuck on this one: <a href="https://stackoverflow.com/a/9142020/696574">Situations where Generics won't work</a></p> <p>Why I end up with covariance problems - is because of my class procedure in my hierarchy.</p> <p>So I'm wondering if Interfaces is my next bold move in this "saga". How do one "step over" a covariance problem. One thing is to find out that you actually have this problem - another thing is "how to work around it".</p> <p>So IF any of you good people "out there" has any opinions on this - I'm all ears. Basically : Tell me to go for Interfaces (I have never done one from scratch myself). Or .. throw me a bone in the direction you would suggest.</p> <p>My current source pool is as stated in the second link - from the top.</p> <p>Here is a small snippet from my earlier <a href="https://stackoverflow.com/q/9140485/696574">post</a> that shows my covariance problem. <a href="https://stackoverflow.com/users/505088/david-heffernan">David</a> kindly explained - Why I ran into the bush.. But now I need info on - How to run around it.</p> <pre><code>var aList : TBaseList&lt;TBaseObject&gt;; // used as a list parameter for methods aPersonList : TPersonList&lt;TPerson&gt;; aCustomerList : TCustomerList&lt;TCustomer&gt;; begin aPersonList := TPersonList&lt;TPerson&gt;.Create; aCustomerList := TCustomerList&lt;TCustomer&gt;.Create; aList := aCustomerList; &lt;-- this FAILS !! types not equal .. end; </code></pre> <p>Regards</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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