Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What Is the Difference Between Using Generics and Using Interfaces (or Abstract Classes)?

0
Posted

What Is the Difference Between Using Generics and Using Interfaces (or Abstract Classes)?

0

Interfaces and generics serve different purposes. Interfaces are about defining a contract between a service consumer and a service provider. As long as the consumer programs strictly against the interface (and not a particular implementation of it), it can use any other service provider that supports the same interface. This allows switching service providers without affecting (or with minimum effect on) the client’s code. The interface also allows the same service provider to provide services to different clients. Interfaces are the cornerstone of modern software engineering, and are used extensively in past and future technologies, from COM to .NET to Indigo and SOA. Generics are about defining and implementing a service without committing to the actual types used. As such, interfaces and generics are not mutually exclusive. Far from it, they compliment each other. You can and you should combine interfaces and generics.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123