4

What is the correct term to describe a type which may be either an interface or an abstract, but is not a concrete type?

This question arises as a result of wiring up StructureMap as an IDependencyResolver for MVC4. I was doing 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 poor method name, which made me wonder if there would be an equally accurate, yet better, term.

STW
  • 44,917
  • 17
  • 105
  • 161
  • 3
    Are they not both *abstractions*? – SpaceBison Mar 27 '13 at 13:21
  • 1
    I prefer to use term abstraction. – Artem Vyshniakov Mar 27 '13 at 13:21
  • They are, so perhaps `abstract` is the best available--but I would guess most C# developers interpret `abstract` as `abstract class`, which made me wonder – STW Mar 27 '13 at 13:22
  • As for down-voters and vote-closers, I believe this question falls within the guidelines. I'm looking for an objective, specific, singular answer related to C# terminology. – STW Mar 27 '13 at 13:30
  • @STW: Before your edits it was not quite there :) Looks fine now. Pity about the close votes. – leppie Mar 27 '13 at 13:35
  • I prefer the term "contract" or "public contract". The contract of a type is used in the same manner, be in class, abstract class, interface, or struct. This is only if I am referring to a usable type. – Adam Houldsworth Sep 08 '15 at 09:19

4 Answers4

3

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

Type type = typeof(IEnumerable); //interface    
Console.WriteLine (type.IsAbstract); //prints true
Ilya Ivanov
  • 23,148
  • 4
  • 64
  • 90
  • This works for me--thanks for finding it in the framework itself, I'll try to remind myself in the future that when someone says `abstract` it may be either--and to nudge people to explicitly say `abstract class` if that's what they mean. – STW Mar 27 '13 at 13:36
1

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

Alan
  • 7,875
  • 1
  • 28
  • 48
0

Maybe abstraction is best, but...

I think you should differentiate between interfaces and abstract classes anyway. Interfaces provide you with a definition of functionality (no implementation), while abstract classes can have partial implementation, and as such is not very different from a normal class (except you can't instantiate it).

On a side note, you may want to read this. This interface has issues in certain conditions.

Community
  • 1
  • 1
L-Four
  • 13,345
  • 9
  • 65
  • 109
-1

In C# terms they are both base types. There isn't really a specific term that describes both.

As for your other question - I would call your code function GetServiceImplementation rather than GetNonConcreteService.

chue x
  • 18,573
  • 7
  • 56
  • 70