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

  • SEARCH
  • Home
  • 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 3606380
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:14:28+00:00 2026-05-18T21:14:28+00:00

I have custom-made wizard system which so far has been quite suitable. For most

  • 0

I have custom-made wizard system which so far has been quite suitable. For most wizards, the pages can be constructed in a fairly generic fashion, so only one class implements those types of pages. However, some need to be custom-designed, so there is an abstract base class for those kinds of pages. Due to some deficiencies in the VS designer, the page can’t itself be a UI control and also be an abstract class with generic parameters (those exist for fluent programming). So one option I’ve followed is to implement the page across two classes, one for the UI (which derives from UserControl and can be designed) and one for the page. The page contains an instance of the UI control and embeds that in itself for display. Not optimal, but it works.

Now, a problem arises from this set up: there is a tight coupling between the UI control class and the page class. This wouldn’t normally be that much of an issue except that pages can be derived from to create specialized versions of the pages. So the derived control and page classes are also tightly coupled with themselves. So when I have member variables, properties and methods on the control and page classes that are typed for the control or page class, respectively (i.e., the control class will have a property Page which points to the page the control is embedded in), we run into a big problem with derived classes. Each derived class must somehow change the type of these members. What I had thought of doing was including a generic type parameter that would allow those members to be generically typed:

public class BaseControl<TControl, TPage>
    where TPage : BasePage<TPage, TControl>
    where TControl : BaseControl<TControl, TPage> {
    public TPage Page { get { ... } set { ... } }
    ...
}

public class BasePage<TPage, TControl>
    where TPage : BasePage<TPage, TControl>
    where TControl : BaseControl<TControl, TPage> {
    public TControl Control { get { ... } set { ... }
    ...
}

public class DerivedControl<TControl, TPage> : BaseControl<TControl, TPage>
    where TControl : DerivedControl<TControl, TPage>
    where TPage : DerivedPage<TPage, TControl> { }

public class DerivedPage<TPage, TControl> : BasePage<TPage, TControl>
    where TControl : DerivedControl<TControl, TPage>
    where TPage : DerivedPage<TPage, TControl> { }

Obviously, this is the kind of C++-style garbage that I’d like to avoid. Besides the ugliness, it creates an actual problem wherein one must create sealed “leaf” classes to work around the infinite recursion problem that CRTP brings us.

And yet the alternatives are also unappealing. I could have those members have a fixed type of the base type and do casting everywhere. This doesn’t enforce type safety and it requires pointless casts (I already know that the type will be such-and-such, but the compiler doesn’t). I could suck it up and combine the page and the control class into one, with no abstract or generic type parameters. That ruins the fluent programming system, or makes it much harder to implement, with much repetition (I’ll explain if needed, but let’s just assume that that part of my design is legitimate).

As such, I’m a bit at a loss for how to do this in a sane manner. Everything I’ve considered so far can be made to work, but the code smell is horrible. Is there something I’m missing, some way of doing this that has so far eluded me?

  • 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-18T21:14:29+00:00Added an answer on May 18, 2026 at 9:14 pm

    I have very similar code in my Protocol Buffers port, where a message type and a builder for that message type are coupled.

    Basically, you’re trying to express a relationship which C# generics makes awkward.

    In my case most of this is hidden in generated code, so the dev doesn’t need to actually do very much… but it’s still ugly. I did look for alternatives, but I didn’t find any. I think what you’ve got may well be as good as you can get, I’m afraid… assuming what you wrote about the VS constraints and your other requirements is correct. If you find yourself able to work in a very different design, that’s great – but if you need the two related types, I think all of this “junk” is required 🙁

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

Sidebar

Related Questions

I have a custom made UINavigationBar (different size, background etc) that has inside a
How can I have a custom home made short URL that performs a 301
I have a custom made class called Graph in which I use adjacency lists.
I have been looking for a easy way to add borders to custom made
I have made a plugin for the iphone which is working fine. I can
I have a custom-made site which I want to migrate to a commercial solution
I have a custom view I made with an IB file since it's quite
I have a custom view I made with an IB file since it's quite
I have a custom made CMS system with a relatively small number (~1000) of
have a custom made slider which I would like to stop on hover. I've

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.