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 809317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:42:33+00:00 2026-05-15T00:42:33+00:00

I am currently facing a very disturbing problem: interface IStateSpace<Position, Value> where Position :

  • 0

I am currently facing a very disturbing problem:

interface IStateSpace<Position, Value>
where Position : IPosition           // <-- Problem starts here
where Value : IValue                 // <-- and here as I don't
{                                    //     know how to get away this
                                     //     circular dependency!
                                     //     Notice how I should be
                                     //     defining generics parameters
                                     //     here but I can't!
    Value GetStateAt(Position position);
    void SetStateAt(Position position, State state);
}

As you’ll down here, both IPosition, IValue and IState depend on each other. How am I supposed to get away with this? I can’t think of any other design that will circumvent this circular dependency and still describes exactly what I want to do!

interface IState<StateSpace, Value>
where StateSpace : IStateSpace        //problem
where Value : IValue                  //problem
{
    StateSpace StateSpace { get; };
    Value Value { get; set; }
}

interface IPosition
{
}

interface IValue<State>
where State : IState {      //here we have the problem again
    State State { get; }
}

Basically I have a state space IStateSpace that has states IState inside. Their position in the state space is given by an IPosition. Each state then has one (or more) values IValue. I am simplifying the hierarchy, as it’s a bit more complex than described. The idea of having this hierarchy defined with generics is to allow for different implementations of the same concepts (an IStateSpace will be implemented both as a matrix as an graph, etc).

Would can I get away with this? How do you generally solve this kind of problems? Which kind of designs are used in these cases?

Thanks

  • 1 1 Answer
  • 1 View
  • 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-15T00:42:33+00:00Added an answer on May 15, 2026 at 12:42 am

    It’s not entirely clear what the problem is – yes, you’ve got circular dependencies in your generic types, but that works.

    I have a similar “problem” in Protocol Buffers: I have “messages” and “builders”, and they come in pairs. So the interfaces look like this:

    public interface IMessage<TMessage, TBuilder>
        where TMessage : IMessage<TMessage, TBuilder> 
        where TBuilder : IBuilder<TMessage, TBuilder>
    

    and

    public interface IBuilder<TMessage, TBuilder> : IBuilder
        where TMessage : IMessage<TMessage, TBuilder> 
        where TBuilder : IBuilder<TMessage, TBuilder>
    

    It’s certainly ugly, but it works. What do you want to be able to express that you can’t currently express? You can see some of my thoughts about this on my blog. (Parts 2 and 3 of the series about Protocol Buffers are the most relevant here.)

    (As an aside, it would make your code more conventional if you would add a T prefix to your type parameters. Currently it looks like State and Value are just classes.)

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

Sidebar

Related Questions

I'm currently facing a problem which I can not resolve and I really don't
I am currently facing a problem. How to get the latest selected value from
Im currently facing the problem that when i try to set focus on some
I'm currently facing new problem with operators. Using following code, I want to make
I am currently facing an error called Bad Base64Coder input character at ... Here
I'm currently facing this problem with ruby on rails 3, devise and facebook oauth.
I'm currently facing a weird problem while executing a command from my bash script.
I'm developing android application with phonegap . Currently I'm facing one problem with inputbox
The problem I'm facing now has totally made me feel like I don't understand
I'm facing the following problem and don't have an answer to it: We have

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.