Hi

As i m new to Daniweb so First of all regards to all experts.
In spite of this that i have used interfaces and abstract classes. I am still not very sure as to where to use them and why to use them.

I will be really thankful if someone provides me with some link which contains complete details of above means history, geography everything.


Thanks N Regards

Varun

Dani AI

Generated

As asked (and as pointed out, MSDN/docs is a good reference), here is a short, practical guide to when to pick an interface versus an abstract class and where you’ll see each used in real projects.

Use an interface when you need a pure contract or a “capability” that many unrelated types can implement. Typical real-world uses: plugin contracts, DI boundaries, framework hooks, and standard behaviors like IDisposable or IEnumerable. Interfaces let different class hierarchies share a common API and are easy to mock for unit tests. See the language guide on interfaces for details: Interfaces.

Use an abstract class when you want a common base that supplies shared code, fields, protected helpers, or constructor logic. Common cases: a base repository that manages DB context, a UI control that provides default rendering, or a test fixture base with setup helpers. Abstract classes are for “is-a” relationships where derived types should inherit behavior as well as the contract: .

A few practical rules of thumb: prefer interfaces for public API boundaries and composition (especially with dependency injection); prefer abstract classes for code reuse and when you need to maintain internal state or expose protected members. Be aware language evolution affects the trade-offs — C# 8 introduced default interface methods, which let interfaces carry implementation but also add complexity; read about that here: C# 8 — default interface methods.

In practice, avoid deep inheritance hierarchies, favour composition, and pick the one that yields clearer, easier-to-test code.

Recommended Answers

All 3 Replies

Realistically if you're looking for information on the various aspects of C# programming (such as class types) I would strongly recommend the msdn.microsoft.com resource site.

Most any information you need regarding how to utilize methods and classes available in C# can be found at that site along with code samples showing their implementation.

Hope this helps :)

Hi Lusiphur

Thanks for replying. I read these articles. Actually i wanted to know where actually interfaces and abstract classes are invincible in real world situation.

Well the articles outline the usage which gives an idea of the reason behind the usage but other than that I guess I'll pass and let someone with more in-depth coding theory knowledge give this one a go :)

Sorry I wasn't much help in this case.

commented: Thanks for Replying +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.