Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the use of blank interfaces a bad design?

I'm considering creating an interface and applying it to all objects in a certain namespace.

Scenario in which I would use this: I want to create a generic handler of those objects, and I'd like to enforce the generic parameter to only accept types that implement this particular interface.

Is this a bad design, or are blank interfaces acceptable?

like image 461
Remus Avatar asked Nov 12 '10 22:11

Remus


2 Answers

What you are talking about doing is known as Marker Interfaces.

I've used this technique successfully in the past, but I would question whether the artificial limitation you are placing on your generic class is actually necessary. If so, then this is certainly a quick and compile checked method of accomplishing it.

like image 125
Chris Shaffer Avatar answered Sep 24 '22 20:09

Chris Shaffer


Nothing wrong with them in my opinion. A lot of their strength lies in combination with (generated) partial classes.

like image 45
Gerrie Schenck Avatar answered Sep 24 '22 20:09

Gerrie Schenck