In ASP.NET and C# I've ran across this before. Your class needs to implement interface ISomething in order for something in the super class to supply something to you.

I can't remember the details, as I ran across it quite a while ago, but it had something to do with session variables in ASP.NET C#. It was part of the .NET framework.

At first, I thought this practice was rather silly and could be more gracefully implemented. However now I'm finding myself implementing this in the architecture of a home-grown project I'm working on. Using reflection, I detect the toggle a behavior on or off based on if it implements ISomething. Just an empty interface with no methods at all.

What is the technical name for this and is it good practice?

3 Answers 3


Marker Interface

Is it good practice? Well, like many things some people love them and some people hate them. See the links in the Wikipedia article for discussion. Personally I think they are rarely useful. The presence of a marker is essentially only a Boolean. It seems preferable to me to define an interface that allows richer information flow and then to pass references using that actual type.


Are you thinking of accessing session state in an .ashx generic handler by implementing the (empty) IRequiresSessionState interface?

I don't know what the technical name for that is. Is it a good practice? Well, I'm not entirely sure why it wasn't done using an attribute.

e.g. instead of:

public class MyGenericHandler : IHttpHandler, IRequiresSessionState


public class MyGenericHandler : IHttpHandler

That certainly seems more intuitive, and more in line with more recently implemented features in ASP.NET and the .NET framework.

  • Yes, that was it! I think i threw up a bit in my mouth when i figured that one out.. For me, its easier to implement IDoesntDoStandardBehavior for something instead of implementing settings for a bunch of classes that behave normally. This is less intrusive.
    – Tyler
    Aug 14, 2012 at 5:31

It's simple--it works with ordinary interfaces. It's used in Java a lot, Java lacking all the bells and whistles of C#. If you use it, you shouldn't even need reflection (unless "is" is part of reflection), just:

if (list is RandomAccess)  element = list[1000000005];
else Consol.WriteLine( "You do not have enough time to wait." )

(The code's C#, RandomAccess is Java. I think.) It can be even simpler, as:

public int GetElement( RandomAccess list )  { ... }

which means you never even have to check for a linked list sneaking though.

And no technology beyond interfaces is needed. It is more of a Java-y thing than a .NET thing. Simple, graceful, clever, and a bit sneaky. Better? Don't know.

  • One clarification that isn't obvious in my post is that i'm doing this in PHP
    – Tyler
    Aug 14, 2012 at 15:08
  • In Java I would if (this instanceof ISomeething)
    – Tyler
    Aug 14, 2012 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.