23.6.13

Talking about C# Interface: in few simple straightforward steps.

Introduction to Interface

 interface just define a general way to represent our requirement as a whole...which can classified in the form empty methods means method without body, simply an interface to something/ to some functionality that you are going to specialize in your further classes. Lets see some common example of Interface.



E.g., There is an animal class. As we know each animal has some common behaviour like
        -> to sleep
        -> to walk
        -> to eat
        -> to meet etc.
e.g.2: In case of our mobile, each mobile phone handset has following common behaviour /function(s)
        -> to connect with network
        -> to Call some number
        -> to let pick any call
        -> to send /receive Message
        -> to manage contacts in phone book, etc.


Now, as per your requirement you can specify about any animal or mobile phone function in its own class, but the behaviours/methods just defined in it would be common to each of its kind.(animal, like dog, cat etc & in case of mobile, Samsung, nokia etc.)

As we know, C# doesn't allow multiple inheritance in the way that we 
have saw in C++ rather it allows us to perform that type of inheritance using Interfaces.

Wrong way: 
Class C: B, A{...}

Correct way:
class clName: Iinterface_name{...} //in C# this process is known as to
                                           //implement an interface

However, here we are talking about interface; what are they & their 
straight forward details:-


Lets know about interface in few simple Steps

-> interface is a mechanism in which we just specify the signatures of 
the methods but no implementation.
-> You can n't define any data member/member variable. Including this 
no method could be 'static'.
-> Any class that implements an interface must give implementation to 
its method which have just been declared.
-> You can n't create of object of any interface.
-> interface is by default/Implicitly public & no access modifier is 
allowed in that.
-> interface can specify methods, property, indexer, events.
-> interface can n't define any constructor, destructor or operator 
method.

Define interface

    public interface Iinterface_name   
    {                                  
        type method one();             
        type method two();             
    }                                  

I want to conclude about this post that it just throw light through simple steps on what actually an interfaces is but not about "how to." However, I would sooner post an updated post which would continue to define inside details of using interface.

Thanks!


[Note:

* You all are welcome to express your views as comment in the box given below of this post. 

* I have not made any special conditions to write here your comment but you may write whatever your heart speak out loud in your inner-self.

* This blog space is continuously in writing/edit mode, kindly keep visiting for a full version]

Post related to CSharp programming
+

No comments:

Post a Comment

Search This Blog

Let make your friend aware about this post