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 ofthe 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
+
- Basics of OOPs (Object Oriented Programming System)
- Straightforward points about Overriding
- C# Method Overloading- in few simple steps with example
- Talking about C# Interface: in few simple straightforward steps
- C# code Abstract method- In few simple straightforard steps
- Select start up project in just 3 steps in visual studio
- Starting with array variable
- whether to press F5 or ctrl+F5 to execute my program.
- How to write c sharp program in 8 simple steps using Visual Studio
- Catching the value of any Kind of Dialog Boxes
- Line Number along with Code in VS2008 / VS2010 / VS2012
No comments:
Post a Comment