Interfaces vs Abstract Classes

preview_player
Показать описание
A popular C# interview question is to explain the differences between interfaces and abstract classes, why use an interface over an abstract class or an abstract class over the interface.

#csharp #dotnet #interview
Рекомендации по теме
Комментарии
Автор

We need more of these interview tips gems

neelamrani
Автор

Best lighting on the tubes, welcome back!

NARY
Автор

Thanks for this video, very informative. Just a couple of questions about Abstract Classes compared to Interfaces. You mentioned that an abstract class is when you have a set of things that have a commonality and then you take that commonality and abstract it into an abstract class. Whereas with interfaces you said you want to separate the thing that a component is dependent on or the things that its consuming and this is where the bridge or contract comes in ultimately used to decouple your components into code. That went straight over my head lol. What I think I have discovered and why some people struggle with getting a sound understanding of the concepts is that maybe its because there is a coding benefit in using abstract classes and interfaces as well as practical advantage.

trustingod
Автор

one thing is, if you wanna change the interface like adding new method / property to it, it will break all implementations. And if you make new interface to replace it, you need to document it and educate other devs in the team. It's disaster especially for package / framework devs. So one important rule would be: If you are going to design an interface, design it very carefully and target it to the future.

lw
Автор

"The Square at that point has schizophrenia "🤣🤣

damilareoyebanji
Автор

Given that this would be a great topic for newer developers to understand better, I think the video would benefit from slowing down a little bit (or reducing the scope, if you want to keep it sub 15 minutes). Don't get me wrong, you are saying a lot of really important thing, but even with 5 years of .NET experience, I had a hard time keeping up on everything.

Noceo
Автор

That's a really great explanation. I think the interviewer wanted this from me. 😅

shashikantnipanikar
Автор

good video, tho i would suggest going/running the code to exarcebate the difference between any 2 approaches. You did show the code, but it's hard to grasp between the 2 without running them

noctavel
Автор

I often inherit an Interface into my Abstract class, then put default implementation into my class. Now, of course, you can do that via default interface implementations, but I don’t recommend doing that, because that’s more of a versioning hack that should be kept in reserve for your Enterprise Architect.

rmcgraw
Автор

One thing that you don’t mention is that creating generic interfaces let you accomplish some pretty great things, via the IN and OUT keywords, by means of covariance and contravariance. That’s probably beyond the scope of this channel, but it’s a good thing to know if you like know what an expert interviewer might follow up this question with.

rmcgraw
Автор

Nothing related to coding, but I like the fact you didn't unwrinkle your t-shirt and don't care about the late afternoon sun removing half of your facial expressions at the beginning of your video.

robsonfaxas
Автор

Great video! I have two more points which were not mentioned (I think? Or maybe I also forgot haha) - A class can implement multiple interfaces, but only one abstract class. Also maybe the fact that default interface implementation methods can't act on any dependencies coming from the implementing class, it's essentially a static context.

allinvanguard
Автор

I noticed I could use public, internal, and protected access modifiers in the interface. I couldn't use private though
Update: doesn't work when inherited from another project. Insisted on public modifiers but worked when implemented 'explicitly' for protected modifiers regardless

oladipotimothy
Автор

🎉 nice seeing your FACE in my notifications

yourockstne
Автор

Hey there! You are missing a "t" on your thumbnail. Welcome back btw!

EdsonViniciusSchmitt
Автор

Hi, pls create a video to explain for Covariant and contravariant

PrasannaCE
Автор

Abstract Base > Inherit > Implement abstracted target interface... avoids issues with dual inheritance. why not just use virtuals?

purplepixeleater
Автор

what's your ide and what theme were you using in this video?

ntson
Автор

I think in C++, you can have multiple inheritance just not Java and C# using abstract classes.

DucaTech
Автор

Sir, please explain bit slow. Content not able to reaching.

ImReddyBasha