Could someone please helpme to understand if the following codes are same. If not what\'s the difference between class and interfance instantiation.
IUnityCo
The object instantiated and stored in the IUnityContainer container
variable is considered by the compiler to have only the members defined in the IUnityContainer
interface. That is, if the UnityContainer
class contains members that aren't defined by the IUnityContainer
interface, you won't be able to invoke them. On the other hand, you could "put" any object that implements the IUnityContainer
interface in the IUnityContainer container
variable--not just instances of UnityContainer
. With the second declaration, you're stuck with instances of UnityContainer
and objects in its inheritance hierarchy.
Check out the C# Programming Guide to Interfaces for more information on interfaces and how they're used.