What do you call an interface with no defining methods used as property setters

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?

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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public class MyGenericHandler : IHttpHandler, IRequiresSessionState
{
}
</code>
<code>public class MyGenericHandler : IHttpHandler, IRequiresSessionState { } </code>
public class MyGenericHandler : IHttpHandler, IRequiresSessionState
{
}

Doing:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>[RequiresSessionState]
public class MyGenericHandler : IHttpHandler
{
}
</code>
<code>[RequiresSessionState] public class MyGenericHandler : IHttpHandler { } </code>
[RequiresSessionState]
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.

1

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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>if (list is RandomAccess) element = list[1000000005];
else Consol.WriteLine( "You do not have enough time to wait." )
</code>
<code>if (list is RandomAccess) element = list[1000000005]; else Consol.WriteLine( "You do not have enough time to wait." ) </code>
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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public int GetElement( RandomAccess list ) { ... }
</code>
<code>public int GetElement( RandomAccess list ) { ... } </code>
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.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật