C# interfaces 🐟

Поделиться
HTML-код
  • Опубликовано: 2 июл 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!");
    }
    }
    }
    }
  • НаукаНаука

Комментарии • 172

  • @BroCodez
    @BroCodez  3 года назад +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 4 месяца назад +22

    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 Год назад +135

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

    • @lazerlight3385
      @lazerlight3385 Год назад

      Teachers are so dumb nowadays

    • @AyushGupta-wn6zd
      @AyushGupta-wn6zd 11 месяцев назад +2

      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 Месяц назад

      adam ol aklını alırım

  • @mojzi1969
    @mojzi1969 16 дней назад +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! 🙏🏿

  • @BlueHat1
    @BlueHat1 Год назад +43

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

  • @jacobsonokoro2173
    @jacobsonokoro2173 2 года назад +48

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

  • @Delmas.
    @Delmas. Месяц назад +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. 🙏

  • @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 RUclips 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.

  • @felipel.r.637
    @felipel.r.637 Год назад +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!

  • @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!

  • @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

  • @despahotaru
    @despahotaru Год назад +2

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

  • @simonroyjonesuk
    @simonroyjonesuk Год назад

    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.

  • @dzulanimashau2781
    @dzulanimashau2781 7 месяцев назад +1

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

  • @gowthamkrishna1568
    @gowthamkrishna1568 Год назад

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

  • @4aliful
    @4aliful 2 года назад +4

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

  • @dineshsthanki
    @dineshsthanki 24 дня назад

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

  • @peternydahl6150
    @peternydahl6150 10 месяцев назад

    Best tutorials! So well planned and pedagogical!

  • @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

  • @xejdikmiecik4137
    @xejdikmiecik4137 Месяц назад

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

  • @adreto2978
    @adreto2978 Год назад

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

  • @mysteryultragames9644
    @mysteryultragames9644 Год назад

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

  • @4citi
    @4citi 8 месяцев назад

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

  • @jhappysemall2269
    @jhappysemall2269 Год назад

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

  • @marcosbettishneider4372
    @marcosbettishneider4372 3 месяца назад

    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.

  • @zetbit
    @zetbit Год назад

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

  • @carloscoelho2547
    @carloscoelho2547 2 года назад

    Simple but great explanation!
    Thank you.

  • @joeorchard3618
    @joeorchard3618 11 месяцев назад

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

  • @tutucaca1
    @tutucaca1 5 месяцев назад

    Quick and simple. Great job!

  • @AlbrechtJ
    @AlbrechtJ Год назад

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

  • @HeadsetHistorian
    @HeadsetHistorian 5 месяцев назад

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

  • @paramjotsingh4019
    @paramjotsingh4019 Год назад

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

  • @ellmister
    @ellmister 3 месяца назад

    A++ Explaination. Helped a lot.

  • @imadabab
    @imadabab Год назад

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

  • @Cherry-jc8bo
    @Cherry-jc8bo Год назад

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

  • @davidchuvik6267
    @davidchuvik6267 Год назад +1

    thank you so much! a concise and clear explanation!

  • @SusanWinters
    @SusanWinters 7 месяцев назад

    Great basic explanation. Thank you!

  • @agustintisera6992
    @agustintisera6992 Год назад

    Very helpful. Thank you!

  • @deeplue1353
    @deeplue1353 2 года назад

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

  • @Mballs2478
    @Mballs2478 6 месяцев назад

    That was really helpful Thank You!

  • @famemovies6738
    @famemovies6738 Год назад

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

  • @DanTheBamJr
    @DanTheBamJr 9 месяцев назад

    thank you for explaining this :)

  • @kekente
    @kekente Год назад

    I finally understand interfaces now. Thanks!

  • @n.a.s1096
    @n.a.s1096 Год назад

    Great explanation - thank you!

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

  • @thetruemystic_
    @thetruemystic_ Год назад

    Just gained a sub for such a clear explanation!

  • @Tyke18
    @Tyke18 8 месяцев назад

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

  • @njourawebdev
    @njourawebdev 5 месяцев назад

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

  • @shadoweagle5843
    @shadoweagle5843 Год назад

    perfect and compact explanation, thanks

  • @julianafranco7749
    @julianafranco7749 Год назад

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

  • @hencobarkhuizen55
    @hencobarkhuizen55 Год назад

    Really good video!

  • @_Ten_
    @_Ten_ Год назад

    Good video. Thank you.

  • @PixelFlicksMovieMagicGaming
    @PixelFlicksMovieMagicGaming 2 года назад

    Tq Dude for explaining in simple way

  • @cherose457
    @cherose457 9 месяцев назад

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

  • @habibasayed6131
    @habibasayed6131 9 дней назад

    you're one of a kind!

  • @amplifiedge
    @amplifiedge Год назад

    Thank you!

  • @MartinPurvis
    @MartinPurvis Год назад

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

  • @manpreetkaur5568
    @manpreetkaur5568 Год назад

    Thanks..Very helpful.

  • @khordad1216
    @khordad1216 2 года назад +6

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

  • @user-dv1xs4qz6k
    @user-dv1xs4qz6k 3 месяца назад

    best explanation with simple example

  • @5hades5hades72
    @5hades5hades72 Год назад

    Amazing bro, thanks

  • @erickgarcia3094
    @erickgarcia3094 9 месяцев назад

    Excellent explanation...

  • @kopilkaiser8991
    @kopilkaiser8991 Год назад

    Bro code you are the best. Keep it up bro

  • @markmirfin4972
    @markmirfin4972 7 месяцев назад +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.

  • @Max-ep7en
    @Max-ep7en Год назад

    your vids are so helpful

  • @leuchuy8602
    @leuchuy8602 8 месяцев назад

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

  • @abidredlove
    @abidredlove Год назад

    it's clear now think you so much

  • @marnierogers3931
    @marnierogers3931 2 года назад

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

  • @prateekbansal9774
    @prateekbansal9774 2 года назад

    Thanks. Really Helpful.

  • @abdullah.nayem.enosisbd
    @abdullah.nayem.enosisbd Год назад

    Thanks!

  • @Zeila1
    @Zeila1 Год назад

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

  • @spartanranger
    @spartanranger 2 года назад

    Thanks for the video Bro.

  • @jayanders1485
    @jayanders1485 Год назад

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

  • @cd-stephen
    @cd-stephen Год назад

    bro!!!! - awesome

  • @mohammadsoliman872
    @mohammadsoliman872 5 месяцев назад

    Thx! I understand now XD

  • @awilson144
    @awilson144 8 месяцев назад

    Thank you

  • @jamiebertrand2669
    @jamiebertrand2669 2 года назад

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

  • @vimukthikulasekara2109
    @vimukthikulasekara2109 4 месяца назад +1

    chad bro saved me thanks man gg

  • @r_amor4767
    @r_amor4767 Год назад

    Killed it

  • @huseyncfrov2514
    @huseyncfrov2514 6 месяцев назад

    "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

  • @user-wm6pe9mm7q
    @user-wm6pe9mm7q Год назад

    thank you it was great!

  • @lwc1
    @lwc1 Год назад

    thanks bro😄

  • @movieecho...4192
    @movieecho...4192 Год назад

    Amazing u r a pro🤩

  • @semihenes9827
    @semihenes9827 2 года назад

    Thanks bro, helped a lot

  • @AzoTup
    @AzoTup 6 месяцев назад

    Thanks

  • @domehankoczki9372
    @domehankoczki9372 Год назад

    Thanks bro

  • @ProphetSac
    @ProphetSac Год назад

    ty

  •  2 года назад

    Thanks Bro!

  • @shadowplayer11.86
    @shadowplayer11.86 Год назад

    You truly are a bro

  • @simonroyjonesuk
    @simonroyjonesuk Год назад

    Is there any chance you could do a video on dependency injection? I'm sure if you did, I could finally understand it.

  • @FullExtension1
    @FullExtension1 Год назад

    You are such a bro, bro.

  • @maxxol4954
    @maxxol4954 Год назад +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?

  • @neo_lowfade3618
    @neo_lowfade3618 10 месяцев назад

    Thanks man now I can be a brogrammer

  • @siddharthaupreti3522
    @siddharthaupreti3522 Год назад

    I love u bro

  • @thomasmontoya302
    @thomasmontoya302 Год назад

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

  • @nadirregragui4690
    @nadirregragui4690 3 месяца назад

    Soldaat!

  • @CSVUTUS
    @CSVUTUS Год назад

    Simple clear fast.

  • @semnal.m2581
    @semnal.m2581 6 месяцев назад

    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.

  • @mikamanelka1326
    @mikamanelka1326 2 года назад

    nice, thx!

  • @khaliderrahaouy5930
    @khaliderrahaouy5930 2 года назад

    thank you