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, 2022 in C# by krishna
• 2,820 points
1,140 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, 2022 in C# by rajiv
• 1,620 points
698 views
0 votes
0 answers

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

As the title states, what are the ...READ MORE

Sep 26, 2022 in C# by krishna
• 2,820 points
304 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, 2022 in C# by rajiv
• 1,620 points
433 views
0 votes
1 answer

Encapsulation vs abstraction real world example

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

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

OOP real world example

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

answered Jul 4, 2022 in C# by krishna
• 2,820 points
1,002 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, 2022 in C# by pranav
• 2,590 points
377 views
0 votes
1 answer

Multiple Inheritance in C#

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

answered Jun 7, 2022 in C# by rajiv
• 1,620 points
567 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, 2022 in C# by jyoti
• 1,240 points
837 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,140 points
5,716 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
1,109 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP