Should an interface only be used to specify certain behavior? Would it be wrong to use interface to group logically related data?

To me it looks like we should not use interface to group logically related data as structure seems a better fit. A class may be used but class name should indicate something like DTO so that user gets the impression that class does not have any behavior.

Please let me know if my assumption is correct.

Also, are there any exceptions where interface can be used to group logically related data?


1 Answer 1


I don't know if I understood correct but interface can be used as generalization for something (hide details) and also can be used as type, which groups some other types.

I recently working on creating simple ORM (for graph database), and I created a lot of empty interfaces just for group specific values. There were simple nodes, extended nodes and special nodes. All of them derived from few interfaces like:

internal interface Node 
    void SetLabel(string label);
    Dictionary<string, object> Properties {get; }
    void AddProperty(string propertyName, object propertyValue);

internal interface SpecificNode : Node {}
internal interface ExtendedNode : Node {}

As you can see, SpecyficNode is just type and doesn't define any behavior.

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