When should I use abstract classes and when should I use interfaces? with considering latest version of C#.NET
Loading
When should I use abstract classes and when should I use interfaces? with considering latest version of C#.NET
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rajanikant HawaldarPosted Sep 8, 2022, 5:13 PM
Rajeev KumarPosted Mar 3, 2023, 7:16 AM
Hi Anand
Abstract classes should be used primarily for objects that are closely related, whereas interfaces are best suited for providing common functionality to unrelated classes. If you are designing small, concise bits of functionality, use interfaces. If you are designing large functional units, use an abstract class.
Alkesh BijarniyaPosted Sep 9, 2022, 6:13 AM
Vishal YelvePosted Sep 9, 2022, 5:53 AM
Jignesh KumarPosted Sep 9, 2022, 3:50 AM
PatelPosted Sep 9, 2022, 2:57 AM
Satish RathorePosted Sep 8, 2022, 3:54 PM
1) when you know scope of requirement use interface and when scope may change or extend use abstract class,
2) when you want all method to be public and force client to implement use interface and when you want different access modifier and do not force to implement on inheritance
3) when you use interface then you simply cannot change it in the end. Abstract classes always have extended compatibility and can still add the behavior without breaking the existing code.