Is it a good/acceptable practice to declare variable as interface type?
<p>Is it a good practice to declare variable using the interface? In my company we had a discussion on it and I'm quite against it.</p>

<p>e.g. I wanted to have a collection storing string keys and string value pairs. I don't want  to allow duplicates either. So clearly I declared Dictionary variable in my class which would be exposed publicly (via property). </p>

<pre><code>Dictionary&lt;string, string&gt; myDic;
</code></pre>

<p>However, a team member says that it's not a good practice ! He is saying that you declare a variable with IDictionary and this will allow consumers to assign any collection (implementing IDictionary) which they want. e.g. Hashtable or Dictionary</p>

<pre><code>IDictionary myDic;
myDic = new Hashtable(); // Consumer's code
</code></pre>

<p>OR </p>

<p><code>mydic = new Dictionary&lt;string, string&gt;(); // Consumer's code</code> -</p>

<p>May I know now, is it really a good practice to declare variable as type of interface? And that too when I clearly know what is expected from that variable?</p>
