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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:11:04+00:00 2026-05-16T12:11:04+00:00

I have a problem with my MVP structure that is built upon generic presenters,

  • 0

I have a problem with my MVP structure that is built upon generic presenters, views etc. and I feel I’m violating DRY and I dont know how to get around it.

Example.

public class Presenter<TView, TModel>
  where TView : IView
  where TModel : Model
{}

So far everything is fine, but I want to have it like this

public class Presenter<TView, TModel>
  where TView : IView
  where TModel : Model
{}

public class Model<T>
{
  public T Value { get;set; }
}

But that won’t compile because the where for Model needs a generic parameter.
The fix:

public class Presenter<TView, TModel, TModelType>
      where TView : IView
      where TModel : Model<TModelType>
    {}

And it’s here I feel i violating dry, take for example

public class MyPresenter : Presenter<IMyView, MyModel, string>
{}

public class MyModel : Model<string>
{}

I feel uncomfortable specifying the string type twice, at the presenter AND at the model,
I only wan’t to specify that the presenter is using MyModel as Model, I don’t care what type of Model (generics). One solution is to remove the generic constraint for the model but then I can’t create a generic Model class hierarchy that I want.

Am I thinking wrong about the whole MVP/generics stuff?

  • 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-16T12:11:05+00:00Added an answer on May 16, 2026 at 12:11 pm

    In C++, this would be solved with a typedef — which C# doesn’t really have.

    public class Model<T>
    {
       typedef T TModelType; // this doesn't exist in C#
       public T Value { get;set; }
    }
    

    Then,

     public class Presenter<TView, TModel>
      where TView : IView
      where TModel : Model<TModel::TModelType>
    {}
    

    There is a type aliasing that you can do with using

    using NewName = any_type<even_generics<with_generics>>
    

    But it’s file based — you can’t use it in a class.

    I would probably do it like this

    1. rename Model<T> to ModelOf<T>
    2. Make a Model base class for ModelOf<T> (ModelOf<T> : Model)
    3. Use where TModel : Model

    Model itself will be useful to define the interface methods that don’t depend on TModelType.

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

Sidebar

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.