C# interfaces 🐟

Поділитися
Вставка
  • Опубліковано 3 лют 2025

КОМЕНТАРІ • 192

  • @BroCodez
    @BroCodez  3 роки тому +84

    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!");
    }
    }
    }
    }

  • @1234crazyskater
    @1234crazyskater 11 місяців тому +72

    Interface declares: "What a class should have"
    An inheriting class defines: "How it should do it"
    Chef's kiss of an explanation, thanks sir

  • @jacobsonokoro2173
    @jacobsonokoro2173 3 роки тому +51

    I have seen other videos, and this is the best explanation i've seen so far. Thanks a lot. I've subscribed.

  • @BlueHat1
    @BlueHat1 2 роки тому +53

    Your explanations are one of the clearest and easiest to remember ones I've ever come across. Great job!

  • @Obalanserad
    @Obalanserad 2 роки тому +180

    My teacher has spent hours confusing this for me. This was so clear

    • @lazerlight3385
      @lazerlight3385 Рік тому

      Teachers are so dumb nowadays

    • @AyushGupta-wn6zd
      @AyushGupta-wn6zd Рік тому +6

      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

    • @MFLBilisim
      @MFLBilisim 9 місяців тому +1

      adam ol aklını alırım

    • @linezich8680
      @linezich8680 4 місяці тому

      Wow you have teacher , interesting 😁

    • @Adi-mw9bz
      @Adi-mw9bz 19 днів тому

      @@MFLBilisim o cikis niye amk haahahaha yoksa o adamin ögretmeni senmisin?

  • @rhr-p7w
    @rhr-p7w 2 роки тому +6

    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!

  • @sgn4862
    @sgn4862 2 роки тому +14

    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 UA-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.

  • @liorlior348
    @liorlior348 Рік тому +10

    Your ability to explain such complicated things so simply is simply amazing to me.
    Thank you for a great channel and quality content!

  • @xejdikmiecik4137
    @xejdikmiecik4137 9 місяців тому +2

    After years, your tutorials still the best
    IPrey for you 🙏

  • @gaminggoddessaria
    @gaminggoddessaria 2 роки тому +12

    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

  • @dzulanimashau2781
    @dzulanimashau2781 Рік тому +1

    I have spent YEARS trying to understand this. today, i fully understood this in 5 minutes . WOW

  • @mojzi1969
    @mojzi1969 8 місяців тому +2

    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! 🙏🏿

  • @Delmas.
    @Delmas. 8 місяців тому +2

    After days of studying and going through lecture material on this topic, I was still clueless until your 5' tutorial came to the rescue. 🙏

  • @despahotaru
    @despahotaru 2 роки тому +2

    Most simple explanation I have seen on interfaces. Thank you!

  • @mysteryultragames9644
    @mysteryultragames9644 Рік тому

    My guy just made an intermediate programming concept seem look like a beginner programming concept. Thank you Mr.Chad.

  • @simonroyjonesuk
    @simonroyjonesuk 2 роки тому

    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.

  • @dineshsthanki
    @dineshsthanki 8 місяців тому

    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. 👏👏👏

  • @jhappysemall2269
    @jhappysemall2269 2 роки тому

    Spent a couple of years learning C# online through UA-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.

  • @gowthamkrishna1568
    @gowthamkrishna1568 Рік тому

    God bless people like you who distill this information down to what is necessary without waffling on.

  • @jayanders1485
    @jayanders1485 2 роки тому +1

    2:16 Rabbit... rabbit... equals new... Rabbit. Made me lol. Excellent video.

  • @blasterxt9
    @blasterxt9 4 місяці тому

    Dude this is one of the best explanations of the interface of c#

  • @4aliful
    @4aliful 3 роки тому +4

    Fantastic explanation and example. It was very clear and understandable!

  • @Cherry-jc8bo
    @Cherry-jc8bo Рік тому

    in just 5 min whole concept is clear...thanks a lot..

  • @MartinPurvis
    @MartinPurvis 2 роки тому

    Seeing video examples is so much better than seeing it being described in text for me

  • @Apature
    @Apature 7 місяців тому

    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 :)

  • @marcosbettishneider4372
    @marcosbettishneider4372 11 місяців тому

    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.

  • @drjones694
    @drjones694 Рік тому

    Great explanation and cliff notes
    Thanks for making the video so short and to the point
    With a real practical example and less theory

  • @deeplue1353
    @deeplue1353 2 роки тому

    WOW, Amazing... i was Struggling for 3 Months. Today i Got the ReaL idea. Thank You So Much

  • @LeonYarovinski
    @LeonYarovinski 2 місяці тому +1

    0:46
    Me: Learning
    My mind: Hawk tuah

  • @famemovies6738
    @famemovies6738 Рік тому

    Great! Saved me alot of time which i was wasting on reading nonscense books!! Now i know what are Interfaces!!!!❤

  • @Tyke18
    @Tyke18 Рік тому

    Best explanation of interfaces i've seen, thankyou :)

  • @kiwibruzzy
    @kiwibruzzy 6 місяців тому +2

    This guy explained in 5 mins what my lecturer took 50 for lmao

  • @AlbrechtJ
    @AlbrechtJ 2 роки тому

    Better than the book I read. Thanks for a clear explanation.

  • @MoHaTa-u3f
    @MoHaTa-u3f 3 місяці тому

    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!

  • @peternydahl6150
    @peternydahl6150 Рік тому

    Best tutorials! So well planned and pedagogical!

  • @imadabab
    @imadabab 2 роки тому

    Best explanation about interfaces. Thanks a lot. I have subscribed.

  • @paramjotsingh4019
    @paramjotsingh4019 2 роки тому

    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...

  • @nwokoeromosele568
    @nwokoeromosele568 Місяць тому

    Very easy to understand.. Thanks bro

  • @winstonsblues
    @winstonsblues 7 місяців тому

    Supreme simplicity, sir.

  • @4citi
    @4citi Рік тому

    This was a clear explanation with great examples. Thank you!

  • @joeorchard3618
    @joeorchard3618 Рік тому

    Was struggling with understanding this thanks for the clear explanation and solid examples :)

  • @ChrisL.Harris
    @ChrisL.Harris 11 місяців тому

    best explanation with simple example

  • @cassioalexsander9725
    @cassioalexsander9725 2 місяці тому

    Very well explained! Thanks!

  • @njourawebdev
    @njourawebdev Рік тому

    that's almost the half part of one of my finals, Thank you

  • @erickgarcia3094
    @erickgarcia3094 Рік тому

    Excellent explanation...

  • @kopilkaiser8991
    @kopilkaiser8991 Рік тому

    Bro code you are the best. Keep it up bro

  • @nadirregragui4690
    @nadirregragui4690 11 місяців тому

    Soldaat!

  • @shadoweagle5843
    @shadoweagle5843 Рік тому

    perfect and compact explanation, thanks

  • @HeadsetHistorian
    @HeadsetHistorian Рік тому

    Thanks, this was a really good approach to explaining the concept.

  • @ellmister
    @ellmister 11 місяців тому

    A++ Explaination. Helped a lot.

  • @alcanyantelcontar6957
    @alcanyantelcontar6957 Місяць тому

    This was amazing

  • @hencobarkhuizen55
    @hencobarkhuizen55 2 роки тому

    Really good video!

  • @zetbit
    @zetbit 2 роки тому

    This code example helped me a lot to understand interfaces, thanks!

  • @Zeila1
    @Zeila1 Рік тому

    this channel is a fucking goldmine. summarises my 1hr lecture into 5mins.

  • @khordad1216
    @khordad1216 3 роки тому +6

    Excellent simple and undrestandable video for beginners or even intermidiate programmers!
    Please do a video on Abtract classes vs Interface Classes.

  • @AthelstanEngland
    @AthelstanEngland Рік тому +1

    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.

  • @Omargamingandtech
    @Omargamingandtech Місяць тому

    great vid

  • @SusanWinters
    @SusanWinters Рік тому

    Great basic explanation. Thank you!

  • @tutucaca1
    @tutucaca1 Рік тому

    Quick and simple. Great job!

  • @movieecho...4192
    @movieecho...4192 2 роки тому

    Amazing u r a pro🤩

  • @Mon93-tt
    @Mon93-tt Рік тому

    I only know a little English and have a lot of difficulty listening to native speakers. Luckily, UA-cam has an automatic translation function :D I'm from Vietnam, the video is really useful.

  • @rebin_daho22
    @rebin_daho22 Місяць тому

    excellent

  • @julianafranco7749
    @julianafranco7749 2 роки тому

    This topic is very weird and this is a very good explanaition, thank you!

  • @aminekarime829
    @aminekarime829 2 роки тому

    Good explenation

  • @spamik7648
    @spamik7648 11 днів тому

    It's pretty basic explanation. If you watch this video you won't really understand why you should use interfaces. Yet it's pretty good to introduce the topic

  • @kekente
    @kekente 2 роки тому

    I finally understand interfaces now. Thanks!

  • @maxmannstein
    @maxmannstein 2 роки тому

    your vids are so helpful

  • @davidchuvik6267
    @davidchuvik6267 2 роки тому +1

    thank you so much! a concise and clear explanation!

  • @johnmaza44
    @johnmaza44 10 місяців тому

    nice video

  • @markmirfin4972
    @markmirfin4972 Рік тому +1

    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.

  • @DanTheBamJr
    @DanTheBamJr Рік тому

    thank you for explaining this :)

  • @thetruemystic_
    @thetruemystic_ 2 роки тому

    Just gained a sub for such a clear explanation!

  • @_Ten_
    @_Ten_ 2 роки тому

    Good video. Thank you.

  • @carloscoelho2547
    @carloscoelho2547 2 роки тому

    Simple but great explanation!
    Thank you.

  • @marnierogers3931
    @marnierogers3931 2 роки тому

    Not a bro but showing support. Thanks for the vid.

  • @n.a.s1096
    @n.a.s1096 Рік тому

    Great explanation - thank you!

  • @PixelFlicksMovieMagicGaming
    @PixelFlicksMovieMagicGaming 3 роки тому

    Tq Dude for explaining in simple way

  • @cimiur
    @cimiur 5 місяців тому

    clear and concise. thanks!

  • @agustintisera6992
    @agustintisera6992 Рік тому

    Very helpful. Thank you!

  • @cd-stephen
    @cd-stephen Рік тому

    bro!!!! - awesome

  • @r_amor4767
    @r_amor4767 Рік тому

    Killed it

  • @huseyncfrov2514
    @huseyncfrov2514 Рік тому

    "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

  • @vimukthikulasekara2109
    @vimukthikulasekara2109 11 місяців тому +1

    chad bro saved me thanks man gg

  • @habibasayed6131
    @habibasayed6131 7 місяців тому

    you're one of a kind!

  • @abidredlove
    @abidredlove Рік тому

    it's clear now think you so much

  • @cherose457
    @cherose457 Рік тому

    Thanks bro. This was the missing link in my game project.

  • @FullExtension1
    @FullExtension1 2 роки тому

    You are such a bro, bro.

  • @manpreetkaur5568
    @manpreetkaur5568 2 роки тому

    Thanks..Very helpful.

  • @neo_lowfade3618
    @neo_lowfade3618 Рік тому

    Thanks man now I can be a brogrammer

  • @glasgood9907
    @glasgood9907 Рік тому +5

    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().

  • @thomasmontoya302
    @thomasmontoya302 Рік тому

    Wow. Usually people need more than one video to win a sub from me, but you got it in just one!

  • @UmarAlFarooq
    @UmarAlFarooq 2 роки тому +1

    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.

  • @5hades5hades72
    @5hades5hades72 Рік тому

    Amazing bro, thanks

  • @seanmeyer5993
    @seanmeyer5993 Рік тому

    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.

  • @CSVUTUS
    @CSVUTUS 2 роки тому

    Simple clear fast.

  • @fralitex2760
    @fralitex2760 2 роки тому +1

    THANKS +1 SUBSCRIBER

  • @spartanranger
    @spartanranger 3 роки тому

    Thanks for the video Bro.

  • @ChrisL.Harris
    @ChrisL.Harris 11 місяців тому

    best best best

  • @黃祐宇
    @黃祐宇 2 роки тому

    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

  • @shadowplayer11.86
    @shadowplayer11.86 Рік тому

    You truly are a bro