Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Development Edition
Design Warnings
 Avoid empty interfaces

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual Studio Team System
Avoid empty interfaces

TypeName

AvoidEmptyInterfaces

CheckId

CA1040

Category

Microsoft.Design

Breaking Change

Breaking

The interface does not declare any members or implement two or more other interfaces.

Interfaces define members that provide a behavior or usage contract. The functionality described by the interface can be adopted by any type, regardless of where the type appears in the inheritance hierarchy. A type implements an interface by providing implementations for the interface's members. An empty interface does not define any members. Therefore, it, does not define a contract that can be implemented.

If your design includes empty interfaces that types are expected to implement, you are probably using an interface as a marker, or a way of identifying a group of types. If this identification will occur at runtime, the correct way to accomplish this is to use a custom attribute. Use the presence or absence of the attribute, or the attribute's properties, to identify the target types. If the identification must occur at compile time, then using an empty interface is acceptable.

Remove the interface or add members to it. If the empty interface is being used to label a set of types, replace the interface with a custom attribute.

It is safe to suppress a warning from this rule if the interface is used to identify a set of types at compile-time.

The following example shows an empty interface.

Visual Basic
Imports System     

Namespace Samples         

    Public Interface IBadInterface  ' Violates rule         
    End Interface     

End Namespace

C#
using System;

namespace DesignLibrary
{
   public interface IBadInterface  // Violates rule
   {
   }
}

Visual C++
#include "stdafx.h"
using namespace System;

namespace Samples
{
    // Violates this rule
    public interface class IEmptyInterface    
    {    
    };
}

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker