C# interfaces 🐟

Sdílet
Vložit
  • čas přidán 2. 07. 2021
  • C# interfaces tutorial example explained
    #C# #interfaces #interface
    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"
    // benefits = 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!");
    }
    }
    }
    }
  • Věda a technologie

Komentáře • 172

  • @BroCodez
    @BroCodez  Před 3 lety +67

    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 Před 4 měsíci +21

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

  • @Obalanserad
    @Obalanserad Před rokem +135

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

    • @lazerlight3385
      @lazerlight3385 Před rokem

      Teachers are so dumb nowadays

    • @AyushGupta-wn6zd
      @AyushGupta-wn6zd Před 10 měsíci +1

      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 Před měsícem

      adam ol aklını alırım

  • @BlueHat1
    @BlueHat1 Před rokem +43

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

  • @jacobsonokoro2173
    @jacobsonokoro2173 Před 2 lety +48

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

  • @mojzi1969
    @mojzi1969 Před 12 dny +1

    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. Před měsícem +1

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

  • @felipel.r.637
    @felipel.r.637 Před rokem +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 Před 2 lety +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 CZcams 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 Před rokem +10

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

  • @dineshsthanki
    @dineshsthanki Před 20 dny

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

  • @simonroyjonesuk
    @simonroyjonesuk Před rokem

    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.

  • @despahotaru
    @despahotaru Před rokem +2

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

  • @gaminggoddessaria
    @gaminggoddessaria Před 2 lety +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 Před 7 měsíci +1

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

  • @4aliful
    @4aliful Před 2 lety +4

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

  • @gowthamkrishna1568
    @gowthamkrishna1568 Před rokem

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

  • @user-dv1xs4qz6k
    @user-dv1xs4qz6k Před 3 měsíci

    best explanation with simple example

  • @peternydahl6150
    @peternydahl6150 Před 10 měsíci

    Best tutorials! So well planned and pedagogical!

  • @adreto2978
    @adreto2978 Před rokem

    Cleared up a lot for my OOP exam tomorrow all from your videos. LEGEND

  • @xejdikmiecik4137
    @xejdikmiecik4137 Před měsícem

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

  • @4citi
    @4citi Před 8 měsíci

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

  • @carloscoelho2547
    @carloscoelho2547 Před 2 lety

    Simple but great explanation!
    Thank you.

  • @drjones694
    @drjones694 Před rokem

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

  • @mysteryultragames9644

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

  • @Cherry-jc8bo
    @Cherry-jc8bo Před rokem

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

  • @AlbrechtJ
    @AlbrechtJ Před rokem

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

  • @marcosbettishneider4372
    @marcosbettishneider4372 Před 3 měsíci

    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.

  • @imadabab
    @imadabab Před rokem

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

  • @zetbit
    @zetbit Před rokem

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

  • @tutucaca1
    @tutucaca1 Před 5 měsíci

    Quick and simple. Great job!

  • @joeorchard3618
    @joeorchard3618 Před 10 měsíci

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

  • @ellmister
    @ellmister Před 3 měsíci

    A++ Explaination. Helped a lot.

  • @davidchuvik6267
    @davidchuvik6267 Před rokem +1

    thank you so much! a concise and clear explanation!

  • @SusanWinters
    @SusanWinters Před 7 měsíci

    Great basic explanation. Thank you!

  • @paramjotsingh4019
    @paramjotsingh4019 Před rokem

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

  • @Tyke18
    @Tyke18 Před 8 měsíci

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

  • @shadoweagle5843
    @shadoweagle5843 Před rokem

    perfect and compact explanation, thanks

  • @PixelFlicksMovieMagicGaming

    Tq Dude for explaining in simple way

  • @jhappysemall2269
    @jhappysemall2269 Před rokem

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

  • @HeadsetHistorian
    @HeadsetHistorian Před 5 měsíci

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

  • @kekente
    @kekente Před rokem

    I finally understand interfaces now. Thanks!

  • @deeplue1353
    @deeplue1353 Před 2 lety

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

  • @Mballs2478
    @Mballs2478 Před 6 měsíci

    That was really helpful Thank You!

  • @famemovies6738
    @famemovies6738 Před rokem

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

  • @n.a.s1096
    @n.a.s1096 Před rokem

    Great explanation - thank you!

  • @agustintisera6992
    @agustintisera6992 Před rokem

    Very helpful. Thank you!

  • @julianafranco7749
    @julianafranco7749 Před rokem

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

  • @DanTheBamJr
    @DanTheBamJr Před 8 měsíci

    thank you for explaining this :)

  • @erickgarcia3094
    @erickgarcia3094 Před 9 měsíci

    Excellent explanation...

  • @thetruemystic_
    @thetruemystic_ Před rokem

    Just gained a sub for such a clear explanation!

  • @_Ten_
    @_Ten_ Před rokem

    Good video. Thank you.

  • @hencobarkhuizen55
    @hencobarkhuizen55 Před rokem

    Really good video!

  • @manpreetkaur5568
    @manpreetkaur5568 Před rokem

    Thanks..Very helpful.

  • @MartinPurvis
    @MartinPurvis Před rokem

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

  • @jayanders1485
    @jayanders1485 Před rokem

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

  • @njourawebdev
    @njourawebdev Před 4 měsíci

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

  • @kopilkaiser8991
    @kopilkaiser8991 Před rokem

    Bro code you are the best. Keep it up bro

  • @spartanranger
    @spartanranger Před 2 lety

    Thanks for the video Bro.

  • @prateekbansal9774
    @prateekbansal9774 Před 2 lety

    Thanks. Really Helpful.

  • @AthelstanEngland
    @AthelstanEngland Před rokem +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.

  • @Max-ep7en
    @Max-ep7en Před rokem

    your vids are so helpful

  • @5hades5hades72
    @5hades5hades72 Před rokem

    Amazing bro, thanks

  • @cherose457
    @cherose457 Před 9 měsíci

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

  • @khordad1216
    @khordad1216 Před 2 lety +6

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

  • @aminekarime829
    @aminekarime829 Před rokem

    Good explenation

  • @awilson144
    @awilson144 Před 8 měsíci

    Thank you

  • @movieecho...4192
    @movieecho...4192 Před rokem

    Amazing u r a pro🤩

  • @amplifiedge
    @amplifiedge Před rokem

    Thank you!

  • @marnierogers3931
    @marnierogers3931 Před 2 lety

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

  • @abidredlove
    @abidredlove Před rokem

    it's clear now think you so much

  • @huseyncfrov2514
    @huseyncfrov2514 Před 6 měsíci

    "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

  • @nadirregragui4690
    @nadirregragui4690 Před 3 měsíci

    Soldaat!

  • @Zeila1
    @Zeila1 Před rokem

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

  • @i.mazanis
    @i.mazanis Před 2 měsíci

    nice video

  • @AzoTup
    @AzoTup Před 6 měsíci

    Thanks

  • @domehankoczki9372
    @domehankoczki9372 Před rokem

    Thanks bro

  • @cd-stephen
    @cd-stephen Před rokem

    bro!!!! - awesome

  • @habibasayed6131
    @habibasayed6131 Před 5 dny

    you're one of a kind!

  • @markmirfin4972
    @markmirfin4972 Před 7 měsíci +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.

  • @r_amor4767
    @r_amor4767 Před rokem

    Killed it

  • @lwc1
    @lwc1 Před rokem

    thanks bro😄

  • @abdullah.nayem.enosisbd

    Thanks!

  • @jamiebertrand2669
    @jamiebertrand2669 Před 2 lety

    Another great tutorial, if you had a patreon, i would definitely support it

  • @user-wm6pe9mm7q
    @user-wm6pe9mm7q Před rokem

    thank you it was great!

  • @CSVUTUS
    @CSVUTUS Před rokem

    Simple clear fast.

  • @maxxol4954
    @maxxol4954 Před rokem +2

    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?

  • @leuchuy8602
    @leuchuy8602 Před 7 měsíci

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

  • @semihenes9827
    @semihenes9827 Před 2 lety

    Thanks bro, helped a lot

  • @vimukthikulasekara2109
    @vimukthikulasekara2109 Před 3 měsíci +1

    chad bro saved me thanks man gg

  • @mohammadsoliman872
    @mohammadsoliman872 Před 5 měsíci

    Thx! I understand now XD

  • @khaliderrahaouy5930
    @khaliderrahaouy5930 Před 2 lety

    thank you

  •  Před 2 lety

    Thanks Bro!

  • @neo_lowfade3618
    @neo_lowfade3618 Před 10 měsíci

    Thanks man now I can be a brogrammer

  • @fralitex2760
    @fralitex2760 Před rokem +1

    THANKS +1 SUBSCRIBER

  • @FullExtension1
    @FullExtension1 Před rokem

    You are such a bro, bro.

  • @siddharthaupreti3522
    @siddharthaupreti3522 Před rokem

    I love u bro

  • @ProphetSac
    @ProphetSac Před rokem

    ty

  • @shadowplayer11.86
    @shadowplayer11.86 Před rokem

    You truly are a bro

  • @user-ig2os8gb6t
    @user-ig2os8gb6t Před 2 lety

    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