in

Chennai .Net User Group

A platform that enables you to Learn, Share & Grow (India's first .Net user group)
Latest post 12-21-2008 3:07 AM by heman_1978. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 12-17-2008 12:38 PM

    • RamSelva
    • Top 50 Contributor
    • Joined on 10-27-2008
    • Posts 2
    • Points 55

    Interface in C#

    Hello friends, I need to clarify about interfaces. Interfaces used in C# to achive multiple inheritance. Ultimately the interface member implemention will be done in the class where the interface is being used. At this scenariao i am not able to understand exactly the need to go for an interface, the same can be achieved by having separate function (Instead of inhering interface and then impement it's members)in the same class. Could you please brief about this with the scenario where do we need to opt for an interface?

     

    Thanks, Rama Selvam M.

  • 12-21-2008 3:07 AM In reply to

    Re: Interface in C#

    Hi Rama Selvam,

    Using interfaces for multiple inheritance is just one advantage. Please understand that the primary purpose of defining is to provide an contract for the implementation. The interface will force you implement certain behaviour (properties, methods and events) on the class that implements it.

    1) when you want to create types for a behavior, like establishing connection to back end, we would create a type of interface and then instantiate the with the required class. This instance variable would allow you to access only those methods that are defined as a part of this interface.

    2) When creating a types that are created from a base class, for every instance of the child class an instance of the base class is also created. So there will be more memory consumption

    3) Interface based program is a key factor for any remote method invokation or RPC like Sevice invocation and Remoting. Though you might have been till date creating the proxies and have been happily coded with it, with the advent of WCF, it is recommended that you start use interface programming. This methodology abides by SOA tenets

    4) There is one more use interface, which is not very common with MS guys is called Marker interface. This is usually used when types have to be grouped. It does not have any behavior defined in it.

     

    Hope this helps

    Venkatesh. S

     

Page 1 of 1 (2 items)
Copyright © 2002-2008 Chennai .Net User Group. All Rights Reserved. Microsoft and Microsoft logo's are trademarks of Microsoft Corporation