Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6015483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:50:32+00:00 2026-05-23T02:50:32+00:00

I want to define an interface IFile that includes an array of key/value pairs

  • 0

I want to define an interface “IFile” that includes an array of key/value pairs “Metadata”. When getting or setting these key/value pairs, the IFile implementor should be able to take action. What would be the best way to go about this? I see three methods:

Method 1) Get/Set a dictionary object:

public interface IFile
{
    ...

    Dictionary<String, String> GetMetadata();

    void SetMetadata(Dictionary<String, String> metadata);
}

Method 2) Use a Dictionary class directly:

public interface IFile
{
    ...

    Dictionary Metadata();
}

and in the implementation of IFile, an inherited version of Dictionary could be provided that acts on get / set.

Method 3) Avoid Dictionary altogether and provide a custom interface, for instance:

public interface IMetadata
{
    String GetValue(String key);        
    void SetValue(String key, String value);        
    Boolean Contains(String key);        
    void Delete(String key);  

    ...
}

public interface IFile
{
    ...

    IMetadata Metadata();
}

I lean towards method 3 because it lets the implementor decide how to actually implement the metadata data structure. The other solutions force the use of a Dictionary. However method 3 seems to involve a lot of extra wrapping code.

I sense that behind this question there is a deeper rooted dilemma when designing class hierarchies, which is whether to expose library classes directly or to expose a few wrapped functions that hides an internally used library class. I have little actual experience in making OOP designs, so advice on what the “Right Way” is in this regard would be very welcome!

Thanks,

Lars

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:50:33+00:00Added an answer on May 23, 2026 at 2:50 am

    If the type of the metadata is known at compile time, then personally I would probably go for this:

    public interface IFile
    {
        ...
    
        IDictionary<string, string> Metadata { get; }
    }
    

    Note – IDictionary instead of Dictionary – that leaves it up to the implementing class as to what type of dictionary implementation to use.

    (I used string for the dictionary type as an example and also because that’s the type you used for IMetadata – change to fit your needs if necessary)

    ps – If the range of keys for the metadata is fixed and relatively small, then make the key an enum – that’s more efficient than string comparisons.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why would I want to define a C++ interface that contains private methods? Even
I want to define injection so that only if the injected interface has EJB
I have an NSWindow that I defined in interface builder. I want to make
I want to define a JavaScript class, Foo. Foo = function(value){ this.value = value;
I want to define an interface MyList which is a list of interface MyThing.
I want to define a min and max methods in a Utils class. @interface
I want to define a behavior on Javascript objects that kicks in when the
While certain guidelines state that you should use an interface when you want to
Every time that I want to do a Layout, I'm getting a black layout
I want to define something like this in php : $EL = \n<br />\n;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.