C# Abstract Classes – What They Are, How to Use Them, and Best Practices



I get asked about abstract classes a lot. What they are, how they work, and why you should know about them. An easy way to think of an abstract class is to say that it fits between a full base class and an interface. Basically, it is a blend of the two. In this video, I am going to demonstrate what an abstract class is, how to use it, and when it makes sense to create an abstract class.

Full courses:
Source Code:
Patreon:
Newsletter signup:

Sponsors:
Tuhafeni Angula (Patreon Subscriber)

Nguồn: https://bdscenter.net

Xem thêm bài viết khác: https://bdscenter.net/game/

40 thoughts on “C# Abstract Classes – What They Are, How to Use Them, and Best Practices

  1. Can you explain how the abstract classes are used to implement a Factory Pattern (btw … is it a pattern?)

  2. My professor is asking me to build a "toolbox" class that contains previously used methods and code in order to call it and use the class in any possible projects in the future. I guess im not understanding wha exactly would go into such class, so i was curious if you've built anything like this?

  3. This is really good explanation. Whole video is good, later part i liked most. Right we should not use concept because it is there but should be very careful on where it fits perfect specially in case with inheritance as it must maintain Is-a relationship. Thanks Tim!

  4. Should the abstract class implement the IDataAccess? Let's say a method returns an IDataAccess instead of DataAccess? Any reason to do that or just complicate things?

  5. Good video. Sometimes I find it challenging to figure out when to choose "composition over inheritance". You mention interfaces here, and also how not to treat a car as if it were a truck. Perhaps a future video delving into how/when to choose composition over inheritance. For example, instead of having a car and truck inherit from an abstract vehicle class, just have them both implement the IDriveable interface? … it's probably one of those situations where there's no right/wrong way, so a video looking at the tradeoffs of doing composition vs inheritance might help. BTW, as I write this I see the Composition Over Inheritance wikipedia page has been flagged as "confusing" since 2015.

  6. Hi Tim, I've been a lead for the past 12 years for 2 to 80 devs teams with tons of junior and mid level developers and I've never been able to explain in an easy and understandable way abstract classes, you nailed it my friend, from now on everytime a dev ask me to explain abstract classes to them I will send them a link to this video and demand from them to donate 5 bucks to your Patreon 😉 Thank you man

  7. Really helpful and awesome for beginners not to struggle, like some of us, later down the road😊! Do you have any “best practices” for designing the sql(or any relational) data structuring? Keep on rocking, C# for life!

  8. Wonderful explanation Sir. Thank you. Do you have any video upload on Generic IEnumerable ?

  9. In C# 8, you can now add default implementations to interfaces, which lets you avoid code repetition without using abstract classes. Though it's mostly meant to add methods to an interface without breaking existing classes that implement it.

  10. Clear explanation and presentation on abstract classes. I like the way you bring the practical side more into your videos rather than presenting only theoretical aspects.

  11. Man, this is really great. I swear I have had so much trouble figuring out abstracts, delegates, and interfaces but these 3 videos changed that. I will be purchasing the full versions of your lessons and learning c# here from now on. I like to re write the code on my own to make sure I understand what each line is doing, and then trying to create my own examples after it helps it stick.

  12. Wow. in 20 minutes I finally understand what an abstract class is. I have over complicated this in the past.

    Are you on Udemy?

  13. Great presentation as usual. But this video would feel a bit "in there" for someone new to OOP in general. I think a longer video on architecting software, where requirements are discussed first before a design is created, will remove any cobwebs surrounding the use of Base classes vs Abstract classes vs Interfaces. Given your teaching style, it would become a definitive video on this subject on YouTube.

  14. For clarity, this chap's tutorials are second to none. He takes a dry subject like 'abstract' classes, breaks it down, gives easy to follow examples and seems to enjoy conveying information to those less experienced than himself. Tim Corey deserves a cyber standing ovation.

  15. that was so perfect oh my god you're like the god of I can teach everything to anyone… amen

  16. Good explanation salute to you I have one question abstraction is an OPPS concept so how to we achive abstraction in our code by using abstract class or interface ?

  17. I have taken many classes, and I can certainly say that you are very good at teaching. It is a pleasure to learn. I will certainly be purchasing classes.

  18. Thanks for this, I have been reading a book that is heavy on the how and light on the why/when. Your concise explanation helped me to understand the use cases for abstract classes better.

  19. Great Video Tim !! How do we decide when to use Abstract class and when to use an interface? Also can we achieve Dependency Inversion through Abstract Class?

  20. Thank you for making this video. It absolutely helped me remove the fog in my mind and made it easy for me to explain Abstract Classes to my son.

  21. Thank you so much for taking your time and making all these videos. Appreciate your efforts !!!
    I would like to know if you are planning to make a video on Reflection ?

  22. Hi Tim, I have a question.

    For initializing objects, we do something like this.

    class Program

    {

    static void Main(string[] args)

    {

    var demo = new DemoClass() {iD=1,Name="vinay" };

    var demo2 = new DemoClass() { iD = 2, Name = "Vikas" };

    var demo3 = new DemoClass { iD = 1, Name = "vinay", Address = "s", number = 3 };

    Console.WriteLine(demo3.Address);

    }

    }

    public class DemoClass

    {

    public int iD { get; set; }

    public string Name { get; set; }

    public int number { get; set; }

    public string Address { get; set; }

    }

    demo2 object is initialized as var demo2 = new DemoClass() { iD = 2, Name = "Vikas" };

    But in demo3 object, I dont use () after new DemoClass but still works fine and gives correct results. Am I doing something wrong here or i didn't understand some concept.

    Thank you for your time.

Leave a Reply

Your email address will not be published. Required fields are marked *