Empty Interface vs. Custom Attributes

  • Thread starter Thread starter Doug Holland
  • Start date Start date
D

Doug Holland

Often you see code where an empty interface is used to
indicate something about the class that realizes it. In
the .NET world this can be done with custom attributes
too, so which is better:

public class SomeClass : IEmptyInterface

or

[Empty]
public class SomeClass
 
I am tempted to agree, however I'm wondering about
performance or other implications which would affect the
decision.

Obviously custom attributes can take arguments which make
them more customizable than empty interfaces.

-----Original Message-----
I prefer custom attributes.
Often you see code where an empty interface is used to
indicate something about the class that realizes it. In
the .NET world this can be done with custom attributes
too, so which is better:

public class SomeClass : IEmptyInterface

or

[Empty]
public class SomeClass


.
 
Doug Holland said:
I am tempted to agree, however I'm wondering about
performance or other implications which would affect the
decision.

Obviously custom attributes can take arguments which make
them more customizable than empty interfaces.

Unless you are processing several million classes, their shouldn't be any
reason to consider performance. Remember, in most casts one in memory
operation is far faster than a single disk load, by orders of magnitude
actually. You only really need to concern yourselft with performance in the
fringe case.

I'd think more about customization and clarity, an attribute provides
metadata, an interface is supposed to provide an interface.
-----Original Message-----
I prefer custom attributes.
Often you see code where an empty interface is used to
indicate something about the class that realizes it. In
the .NET world this can be done with custom attributes
too, so which is better:

public class SomeClass : IEmptyInterface

or

[Empty]
public class SomeClass


.
 
I think attributes are much more "cleaner", they provide you with a greate
flexibility. You need one interface for each "type", using attributes you
can reduce the number by reusing attributes (giving them a property), for
example

[Empty(CanDoThis)]
public class SomeClass

[Empty(CanDoSomethingElse)]
public class SomeClass


--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
Doug Holland said:
I am tempted to agree, however I'm wondering about
performance or other implications which would affect the
decision.

Obviously custom attributes can take arguments which make
them more customizable than empty interfaces.

-----Original Message-----
I prefer custom attributes.
Often you see code where an empty interface is used to
indicate something about the class that realizes it. In
the .NET world this can be done with custom attributes
too, so which is better:

public class SomeClass : IEmptyInterface

or

[Empty]
public class SomeClass


.
 
Thanks Guys

I had the same feelings about custom attributes but being
a recent father and being sleep deprived I wanted
to 'sanity-check' my thoughts ;)

- Doug
-----Original Message-----
I think attributes are much more "cleaner", they provide you with a greate
flexibility. You need one interface for each "type", using attributes you
can reduce the number by reusing attributes (giving them a property), for
example

[Empty(CanDoThis)]
public class SomeClass

[Empty(CanDoSomethingElse)]
public class SomeClass


--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
"Doug Holland" <[email protected]> schreef in bericht
I am tempted to agree, however I'm wondering about
performance or other implications which would affect the
decision.

Obviously custom attributes can take arguments which make
them more customizable than empty interfaces.

-----Original Message-----
I prefer custom attributes.
"Doug Holland" <[email protected]>
wrote
in message
Often you see code where an empty interface is used to
indicate something about the class that realizes it. In
the .NET world this can be done with custom attributes
too, so which is better:

public class SomeClass : IEmptyInterface

or

[Empty]
public class SomeClass



.


.
 
Back
Top