using System; namespace MyFirstProgram { class Program { static void Main(string[] args) { // interface = defines a "contract" that all the classes inheriting from should follow // An interface declares "what a class should have" // An inheriting class defines "how it should do it" // Benefit = security + multiple inheritance + "plug-and-play" Rabbit rabbit = new Rabbit(); Hawk hawk = new Hawk(); Fish fish = new Fish(); rabbit.Flee(); hawk.Hunt(); fish.Flee(); fish.Hunt(); Console.ReadKey(); } interface IPrey { void Flee(); } interface IPredator { void Hunt(); } class Rabbit : IPrey { public void Flee() { Console.WriteLine("The rabbit runs away!"); } } class Hawk : IPredator { public void Hunt() { Console.WriteLine("The hawk is searching for food!"); } } class Fish : IPrey, IPredator { public void Flee() { Console.WriteLine("The fish swims away!"); } public void Hunt() { Console.WriteLine("The fish is searching for smaller fish!"); } } } }
Zero BS, straight to the point. After watching your video I inmediately understood how to refactor my existing programs using Interfaces. Thank you very much!
getting into programing for game development as I have always been fascinated by it and your vids are the best I have found. You explain it in such a way that actually helps me learn. Most coding videos on TH-cam are so hard to listen to as they don't know how to communicate their skills properly. But I thank you for doing such a good job with it as your videos help me a lot.
This helped me so much I was so confused having to do this at my internship and I got the hang of it in 5 minutes because you explained this so well! Thank thank you
Bravo !!! Finally, someone’s demonstrated a concept without making the example so simple that you do not, first have to grapple your mind with the details of the example to understand the underlying concept. It is very rare to find an engineer who can communicate an idea concisely without confusing everyone. 👏👏👏
Great video thanks. I think thats the first time I understand what an interface does. Everyone keeps talking about contracts, but you are the first person to explain it in a way I can understand.
Spent a couple of years learning C# online through TH-cam videos, I learned alot to the point where I created a console program to make pizzas from scratch. The program I wrote allowed me to input keys to the console that allowed option selection. I learned that through Michael Hadley's Intro to Programming tutorials. However I struggled like a muddabucka with a few things to this day. Interfaces being one them. Today I am on Unity exploring real game design, and their lesson courses are amazing. All the C# know-how I learned proved worth it, because I am flying through the courses - because Unity's documentation doe alot of work for you. But there was a course that used IEnumerators in Unity. Sure I understood what the IEnumerator as for - but I still never understood Interfaces themselves. Now I do thanks to your video. And i's such a clear and easy concept i feel so dumb tonot have grasped them before. But thanks man! ... I mean... Bro.
I was so stuck on this topic, reading from a book and it wasnt overly clear, You my good sir gave me a eureka moment. Thank you so much, Liked and subed :)
This seems extremely useful when making games and programs in general! Sometimes a class/object might be of another type as well, and need a certain method (etc.). This helps you to not forget to add the method. For example, in a survival game: Birds, cattle, humans, and fish are all organisms. They all need a method to "eat" to survive. If you forget to add a "eat" method, one of them might die of hunger with no way to keep them alive!
Thank you very much. I'm from Brazil, and I know a litlle bit English, and these help me to understand what you were explaining, and the form how you were explaining was so simple, I could learn about the interfaces.
Video clip explains how to implement C# interfaces but still doesn't give any insight as when it's best used. For example, could have been better explained that the Hawk sweeps into a shoal if fish within the sea, the shoal of fish is made up of many different types of fish, but all of the fish have an Eatable() method that is defined within the interface IPray, the Hawk doesn't care what type of fish it is, only that it has a Eatable() method. Or think in game terms, there are many types of enemy in the game such as Zombie, Witch, AxeMan. all those enemy's killable() method is exposed through a interface. So the player fires a burst of bullets and kills enemy via an interface to the killable() method. So using an interface if a far better way of using if else statments such as if(Zombie || Witch || AxeMan ) destroy().
Thanks very clear. The multiple inheritance is good. But in my experience it seems most projects tend to have a one-to-one model where each class has an interface all to itself that is never implemented elsewhere, hence overkill.
Good video. Just one point, a class is said to implement an interface and to inhererit from another class. Also, it would be good if you perhaps demonstrated why a dev may choose to use interfaces. E.g. polymorphism and dependency injection, for example.
I only know a little English and have a lot of difficulty listening to native speakers. Luckily, TH-cam has an automatic translation function :D I'm from Vietnam, the video is really useful.
I don't understand what the itnerface actually does. by defining the method of fleeing and hunting in every class does that not make the inheritance obsolete?
I would like for you to please please expound on the "benefits" of using interfaces. Just seems like additional work. Why would I ever NEED to implement them? I've heard "dependency injection" but I'm still not able to wrap my mind around why would I spend extra time creating interfaces when I can just create the methods.
I'm confused. I mean wouldn't everything run the same if you removed the interface? Couldn't you also get the same security by making those methods private and using getters? I still don't understand the practical reason for using an interface.
I think I've understood how interfaces work in that they specify what an inheriting class must implement, but what's the advantage of interfaces here over simple class inheritance? Like Predator and Prey could be classes instead of interfaces, and the various animals could just inherit from them.
I wish learning programming was done with examples and a straight forward approach like this instead of hundreds of pages reading about nothing but confusion.
In the example, how would it be if you have the Hawk hunt a prey, specifying IPrey as an argument to Hawk? Like Hawk hunts a rabbit and later a a fish. This way you just specifyy IPrey as an argument type but you can feed whatever to it as long as it's a prey. Additionally you would have specified in IPrey what a prey animal's specifications should be.
Excellent explanations! Thank you. So far everything is very clear. Now, suppose we have two classes Circle and Triangle that implement interfaces IShape. How can I save the two or more classes in one xml file. What do I need to do? Can you provide an example? No one shows us ways to save as a file that can be reused later.
Hello. Thank you for the video. I'm still learning C sharp and currently struggling with understanding interfaces and why they exist, how to use them etc... And even tho your example is easy to understand, you can still completely delete the interface declaration and all the IPrey and IPredator everywhere and it will all still work. The interface in your example is not used at all. You declared methods for each class and you are just calling these methods within the classes in your main method. Or am I missing something?
using System;
namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
// interface = defines a "contract" that all the classes inheriting from should follow
// An interface declares "what a class should have"
// An inheriting class defines "how it should do it"
// Benefit = security + multiple inheritance + "plug-and-play"
Rabbit rabbit = new Rabbit();
Hawk hawk = new Hawk();
Fish fish = new Fish();
rabbit.Flee();
hawk.Hunt();
fish.Flee();
fish.Hunt();
Console.ReadKey();
}
interface IPrey
{
void Flee();
}
interface IPredator
{
void Hunt();
}
class Rabbit : IPrey
{
public void Flee()
{
Console.WriteLine("The rabbit runs away!");
}
}
class Hawk : IPredator
{
public void Hunt()
{
Console.WriteLine("The hawk is searching for food!");
}
}
class Fish : IPrey, IPredator
{
public void Flee()
{
Console.WriteLine("The fish swims away!");
}
public void Hunt()
{
Console.WriteLine("The fish is searching for smaller fish!");
}
}
}
}
OMG, You are Amazing..
? ing - isn't a verb! Algiers racism - kidnap ID!
Interface declares: "What a class should have"
An inheriting class defines: "How it should do it"
Chef's kiss of an explanation, thanks sir
Your explanations are one of the clearest and easiest to remember ones I've ever come across. Great job!
My teacher has spent hours confusing this for me. This was so clear
Teachers are so dumb nowadays
well, it is a bit more complicated than that. We can create a class object by using an interface and criss cross stuff. It becomes a bit complicated
adam ol aklını alırım
Wow you have teacher , interesting 😁
I have seen other videos, and this is the best explanation i've seen so far. Thanks a lot. I've subscribed.
Zero BS, straight to the point. After watching your video I inmediately understood how to refactor my existing programs using Interfaces. Thank you very much!
getting into programing for game development as I have always been fascinated by it and your vids are the best I have found. You explain it in such a way that actually helps me learn. Most coding videos on TH-cam are so hard to listen to as they don't know how to communicate their skills properly. But I thank you for doing such a good job with it as your videos help me a lot.
Your ability to explain such complicated things so simply is simply amazing to me.
Thank you for a great channel and quality content!
After years, your tutorials still the best
IPrey for you 🙏
In an hour i'm writing an exam based on this. 10 minutes ago I knew shit about interfaces, now I know all I need. Huge thanks goes to this man! 🙏🏿
This helped me so much I was so confused having to do this at my internship and I got the hang of it in 5 minutes because you explained this so well! Thank thank you
After days of studying and going through lecture material on this topic, I was still clueless until your 5' tutorial came to the rescue. 🙏
I have spent YEARS trying to understand this. today, i fully understood this in 5 minutes . WOW
Bravo !!! Finally, someone’s demonstrated a concept without making the example so simple that you do not, first have to grapple your mind with the details of the example to understand the underlying concept. It is very rare to find an engineer who can communicate an idea concisely without confusing everyone. 👏👏👏
Great video thanks. I think thats the first time I understand what an interface does. Everyone keeps talking about contracts, but you are the first person to explain it in a way I can understand.
Spent a couple of years learning C# online through TH-cam videos, I learned alot to the point where I created a console program to make pizzas from scratch. The program I wrote allowed me to input keys to the console that allowed option selection. I learned that through Michael Hadley's Intro to Programming tutorials.
However I struggled like a muddabucka with a few things to this day. Interfaces being one them. Today I am on Unity exploring real game design, and their lesson courses are amazing. All the C# know-how I learned proved worth it, because I am flying through the courses - because Unity's documentation doe alot of work for you. But there was a course that used IEnumerators in Unity.
Sure I understood what the IEnumerator as for - but I still never understood Interfaces themselves. Now I do thanks to your video. And i's such a clear and easy concept i feel so dumb tonot have grasped them before.
But thanks man! ... I mean... Bro.
I was so stuck on this topic, reading from a book and it wasnt overly clear, You my good sir gave me a eureka moment. Thank you so much, Liked and subed :)
My guy just made an intermediate programming concept seem look like a beginner programming concept. Thank you Mr.Chad.
Most simple explanation I have seen on interfaces. Thank you!
God bless people like you who distill this information down to what is necessary without waffling on.
Fantastic explanation and example. It was very clear and understandable!
2:16 Rabbit... rabbit... equals new... Rabbit. Made me lol. Excellent video.
Dude this is one of the best explanations of the interface of c#
WOW, Amazing... i was Struggling for 3 Months. Today i Got the ReaL idea. Thank You So Much
in just 5 min whole concept is clear...thanks a lot..
Cleared up a lot for my OOP exam tomorrow all from your videos. LEGEND
I am starting to love your videos... They are short, precise... AND VERY EASY TO UNDERSTAND THE WAY YOUUUU EXPLAIN IT!!! Keep the great work BRO...
This seems extremely useful when making games and programs in general! Sometimes a class/object might be of another type as well, and need a certain method (etc.). This helps you to not forget to add the method.
For example, in a survival game:
Birds, cattle, humans, and fish are all organisms. They all need a method to "eat" to survive. If you forget to add a "eat" method, one of them might die of hunger with no way to keep them alive!
Thank you very much. I'm from Brazil, and I know a litlle bit English, and these help me to understand what you were explaining, and the form how you were explaining was so simple, I could learn about the interfaces.
This guy explained in 5 mins what my lecturer took 50 for lmao
Seeing video examples is so much better than seeing it being described in text for me
Great explanation and cliff notes
Thanks for making the video so short and to the point
With a real practical example and less theory
Great! Saved me alot of time which i was wasting on reading nonscense books!! Now i know what are Interfaces!!!!❤
Video clip explains how to implement C# interfaces but still doesn't give any insight as when it's best used. For example, could have been better explained that the Hawk sweeps into a shoal if fish within the sea, the shoal of fish is made up of many different types of fish, but all of the fish have an Eatable() method that is defined within the interface IPray, the Hawk doesn't care what type of fish it is, only that it has a Eatable() method. Or think in game terms, there are many types of enemy in the game such as Zombie, Witch, AxeMan. all those enemy's killable() method is exposed through a interface. So the player fires a burst of bullets and kills enemy via an interface to the killable() method. So using an interface if a far better way of using if else statments such as if(Zombie || Witch || AxeMan ) destroy().
Best explanation of interfaces i've seen, thankyou :)
Better than the book I read. Thanks for a clear explanation.
Best explanation about interfaces. Thanks a lot. I have subscribed.
Best tutorials! So well planned and pedagogical!
This was a clear explanation with great examples. Thank you!
0:46
Me: Learning
My mind: Hawk tuah
...
Was struggling with understanding this thanks for the clear explanation and solid examples :)
Very easy to understand.. Thanks bro
Thanks very clear. The multiple inheritance is good. But in my experience it seems most projects tend to have a one-to-one model where each class has an interface all to itself that is never implemented elsewhere, hence overkill.
Good video. Just one point, a class is said to implement an interface and to inhererit from another class. Also, it would be good if you perhaps demonstrated why a dev may choose to use interfaces. E.g. polymorphism and dependency injection, for example.
Excellent simple and undrestandable video for beginners or even intermidiate programmers!
Please do a video on Abtract classes vs Interface Classes.
that's almost the half part of one of my finals, Thank you
I only know a little English and have a lot of difficulty listening to native speakers. Luckily, TH-cam has an automatic translation function :D I'm from Vietnam, the video is really useful.
I don't understand what the itnerface actually does. by defining the method of fleeing and hunting in every class does that not make the inheritance obsolete?
This code example helped me a lot to understand interfaces, thanks!
Thanks, this was a really good approach to explaining the concept.
best explanation with simple example
Quick and simple. Great job!
"The world isn't perfect. But it's there for us, doing the best it can....that's what makes it so damn beautiful" - Roy Mustang
This topic is very weird and this is a very good explanaition, thank you!
this channel is a fucking goldmine. summarises my 1hr lecture into 5mins.
Very well explained! Thanks!
Great basic explanation. Thank you!
Bro code you are the best. Keep it up bro
A++ Explaination. Helped a lot.
Supreme simplicity, sir.
I would like for you to please please expound on the "benefits" of using interfaces. Just seems like additional work. Why would I ever NEED to implement them? I've heard "dependency injection" but I'm still not able to wrap my mind around why would I spend extra time creating interfaces when I can just create the methods.
thank you so much! a concise and clear explanation!
I'm confused. I mean wouldn't everything run the same if you removed the interface? Couldn't you also get the same security by making those methods private and using getters? I still don't understand the practical reason for using an interface.
I finally understand interfaces now. Thanks!
perfect and compact explanation, thanks
A lot of bad explaining resources out there, this video is one of the best. My only wish would be ‘how would you use this in a game?’
Hai bro,Your explanation is very clear.
Can you explain why we need interface?
Why we need to use it other than class?
Tq Dude for explaining in simple way
Just gained a sub for such a clear explanation!
Simple but great explanation!
Thank you.
Excellent explanation...
Really good video!
Amazing u r a pro🤩
Great explanation - thank you!
This was amazing
Not a bro but showing support. Thanks for the vid.
I think I've understood how interfaces work in that they specify what an inheriting class must implement, but what's the advantage of interfaces here over simple class inheritance? Like Predator and Prey could be classes instead of interfaces, and the various animals could just inherit from them.
I wish learning programming was done with examples and a straight forward approach like this instead of hundreds of pages reading about nothing but confusion.
thank you for explaining this :)
Thanks bro. This was the missing link in my game project.
Very helpful. Thank you!
your vids are so helpful
Wow. Usually people need more than one video to win a sub from me, but you got it in just one!
Good explenation
In the example, how would it be if you have the Hawk hunt a prey, specifying IPrey as an argument to Hawk? Like Hawk hunts a rabbit and later a a fish. This way you just specifyy IPrey as an argument type but you can feed whatever to it as long as it's a prey. Additionally you would have specified in IPrey what a prey animal's specifications should be.
clear and concise. thanks!
great vid
Good video. Thank you.
Soldaat!
chad bro saved me thanks man gg
Thanks..Very helpful.
THANKS +1 SUBSCRIBER
Excellent explanations! Thank you. So far everything is very clear.
Now, suppose we have two classes Circle and Triangle that implement interfaces IShape.
How can I save the two or more classes in one xml file. What do I need to do? Can you provide an example?
No one shows us ways to save as a file that can be reused later.
you're one of a kind!
Have not described the reasons for using interfaces... How is here, why is not !
Damm, I couldn't understand what that is for months in my uni, and I suddenly understand it in 5 min after finding this viedo
nice video
excellent
Wondering if the animals would be REQUIRED to implement the methods or not.
Hello. Thank you for the video. I'm still learning C sharp and currently struggling with understanding interfaces and why they exist, how to use them etc...
And even tho your example is easy to understand, you can still completely delete the interface declaration and all the IPrey and IPredator everywhere and it will all still work. The interface in your example is not used at all. You declared methods for each class and you are just calling these methods within the classes in your main method.
Or am I missing something?