Use of interfaces practical and real world example

0 votes

I've been attempting to figure out what interfaces are, and in principle, I've absorbed the term rather well. However, when it comes to actually employing them, I have some concerns.

The following is how most resources define interface:

"An interface is a contract that exists between the interface and any class that implements it." Any class that implements the interface must implement the interface's properties, methods, and/or events, according to this contract. There is no implementation in an interface; only the signatures of the functionality it provides. Method signatures, attributes, indexers, and events can all be found in an interface."

This is really clear, but my issue is: if interfaces are (according to this definition) a kind of blueprint or contract between themselves and classes, what happens if I define this interface, for example?

interface ITest {
    int SomeTestVariable { set; get;}
    int SomeTestMethod ();    
}

Create a class that implements both the interface and all of its methods.

class Test: ITest {
    int SomeTestvariable { set; get;}
    int SomeTestMethod () {
        return 1;
    }   
}

I remove it once all of the methods and attributes have been implemented.

class Test {
    int SomeTestvariable { set; get;}
    int SomeTestMethod () {
        return 1;
    }   
}

Now I need to find a class that's used this blueprint or contract. So, what's the difference between drawing this blueprint on paper and creating an interface?

Jun 11 in C# by krishna
• 2,540 points
5 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In C#

0 votes
1 answer

What are the differences between C, C# and C++ in terms of real-world applications?

C is a bare-bones, straightforward, and clean ...READ MORE

answered May 30 in C# by rajiv
• 1,620 points
29 views
0 votes
1 answer

C# - Can someone please show me a very simple example of Interfaces

Take this as example interface IFlyable { ...READ MORE

answered May 30 in C# by rajiv
• 1,620 points
24 views
0 votes
1 answer

Encapsulation vs abstraction real world example

Encapsulation is a technique for "information concealment," ...READ MORE

answered Jun 21 in C# by jyoti
• 1,240 points
38 views
0 votes
1 answer

OOP real world example

This is what I believe. OOP does not ...READ MORE

answered Jul 4 in C# by krishna
• 2,540 points
17 views
0 votes
0 answers

When to use an interface instead of an abstract class and vice versa

This could be an OOP question in ...READ MORE

Jun 11 in C# by pranav
• 2,580 points
13 views
0 votes
1 answer

Which design pattern to use for pre-process process and post-process task

You have pre-defined and precise steps to ...READ MORE

answered Jun 9 in C# by rajiv
• 1,620 points
30 views
0 votes
1 answer

Multiple Inheritance in C#

The.net Framework CLR and C# hasn't been ...READ MORE

answered Jun 7 in C# by rajiv
• 1,620 points
28 views
0 votes
1 answer

I don't understand inheritance with base classes

If you just want to keep a ...READ MORE

answered Jun 17 in C# by jyoti
• 1,240 points
18 views
0 votes
3 answers

Trying to upload files using Selenium(C#)

You can try using Javascript Executor to ...READ MORE

answered Aug 23, 2019 in Selenium by Abha
• 28,120 points
4,511 views
0 votes
1 answer

Deploy my Windows 10 IOT core application locally!

Of course, you, can! That is, in ...READ MORE

answered Jul 17, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
516 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP