Is there a term that interchangeably describes either an interface or an abstract class in C #?

What is the correct term for describing a type, which can be either an interface or an abstract, but not a specific type?

This question arises as a result of connecting StructureMap as an IDependencyResolver for MVC4. I did a little refactoring and created this:

 public object GetService(Type serviceType) { if (serviceType.IsAbstract || serviceType.IsInterface) { return GetNonConcreteService(serviceType); } return GetConcreteService(serviceType); } private object GetConcreteService(Type serviceType) { return _container.GetInstance(serviceType); } private object GetNonConcreteService(Type serviceType) { return _container.TryGetInstance(serviceType); } 

Obviously, GetNonConcreteService is a bad method name, which made me wonder if the same exact but better term would be.

+4
source share
4 answers

To answer your code examples, they are all called Abstraction in .net . To demonstrate this:

 Type type = typeof(IEnumerable); //interface Console.WriteLine (type.IsAbstract); //prints true 
+3
source

Perhaps you could call them both abstractions. An interface defines a set of methods / properties / events that you must define if you are implementing an interface. An abstract class can implement functionality, but also define abstract methods that are similar to the interfaces that must be implemented if you inherit an abstract class. The difference is that an abstract class can provide some functionality.

+1
source

Maybe abstraction is best, but ...

I think that in any case, you should distinguish between interfaces and abstract classes. Interfaces provide you with a definition of functionality (without implementation), while abstract classes can have a partial implementation and, as such, are not very different from a regular class (except that you cannot create it).

On the other hand, you can read this one . This interface has problems in certain conditions.

0
source

In C # terms, they are basic. In fact, there is no particular term that describes both.

As for your other question - I would call your code function GetServiceImplementation , not GetNonConcreteService .

-1
source

All Articles