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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:58:22+00:00 2026-05-23T21:58:22+00:00

I was looking into using the to implement the style and rendering in a

  • 0

I was looking into using the to implement the style and rendering in a little GUI toolkit of mine using the Factory Pattern, and then this crazy Idea struck me. Why not use the Factory Pattern for all widgets?

Right now I’m thinking something in style of:

Widget label = Widget::create("label", "Hello, World");
Widget byebtn = Widget::create("button", "Good Bye!");

byebtn.onEvent("click", &goodByeHandler);

New widget types would be registered with a function like Widget::register(std::string ref, factfunc(*fact))

What would you say is the pros and cons of this method?

I would bet on that there is almost no performance issues using a std::map<std::string> as it is only used when setting things up.

And yes, forgive me for being damaged by JavaScript and any possible syntax errors in my C++ as it was quite a while since I used that language.


Summary of pros and cons

Pros

  • It would be easy to load new widgets dynamically from a file
  • Widgets could easily be replaced on run-time (it could also assist with unit testing)
  • Appeal to Dynamic People

Cons (and possible solutions)

  • Not compile-time checked (Could write own build-time check. JS/Python/name it, is not compile-time checked either; and I believe that the developers do quite fine without it)
  • Perhaps less performant (Do not need to create Widgets all the time. String Maps would not be used all the time but rather when creating the widget and registering event handlers)
  • Up/Downcasting hell (Provide usual class instantiation where needed)
  • Possible of making it harder to configure widgets (Make widgets have the same options)

My GUI Toolkit is in its early stages, it lacks quite much on the planning side. And as I’m not used to make GUI frameworks there is probably a lot of questions/design decisions that I have not even though of yet.

Right now I can’t see that widgets would be too different in their set of methods, but that might rather just be because I’ve not gone trough the more advanced widgets in my mind yet.

Thank you all for your input!

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

    Pros

    • It would be easy to read widgets from file or some other external source and create them by their names.

    Cons

    • It would be easy to pass incorrect type name into Widget::create and you’ll get error in run-time only.
    • You will have no access to widget-specific API without downcasting – i.e. one more source of run-time errors.
    • It might be not that easy to find all places where you create a widget of particular type.

    Why not get best of both worlds by allowing widget creation both with regular constructors and with a factory?

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

Sidebar

Related Questions

I'm looking into using the jQuery UI autocomplete widget to implement user lookup by
I have a question. Recently I was looking into ways to implement hardware rendering
I'm looking into using Visual Studio 2008's built in unit test projects instead of
I was looking into using some .NET code from within a Delphi program, I
I'm looking into using Lucene and/or Solr to provide search in an RDBMS-powered web
I am looking into using only a ddl to run my query, not a
I'm looking into why a managed process is using a lot of memory. Is
I was looking into the possibility of using CouchDB. I heard that it was
I have been looking into IKVMing Apache's FOP project to use with our .NET
I've recently been looking into targeting the .NET Client Profile for a WPF application

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.