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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:29:11+00:00 2026-06-17T09:29:11+00:00

I heard that it is better to separate data and GUI. For examples, I

  • 0

I heard that it is better to separate data and GUI. For examples, I have some data. It is hierarchical with abstract base and derived class for concrete types, like

class Data {};
class ConcreteDataA : public Data {};
class ConcreteDataB : public Data {};

And I also have its hierarchical GUI (for example dialog)

class DataDialog {};
class ConcreteDataADialog : public DataDialog {};
class ConcreteDataBDilaog : public DataDialog {};

And I want create a data dialog object from a data object. If the data object is ConcreteDataA, ConcreteDataADialog is created, if B, B dialog is created. There is an easy way to do it by adding a virtual function in class Data like

virtual DataDialog* CreateDialog()

But if I add this function in the data class. it seems to violate the data/GUI separation principle. The second way is to build a global CreateDialog function, and create dialogs according to the dynamic_cast type of data object. This way is also not good for many maual ifs. Any other way to implement it? Or in practice, the first way is also okay? Thanks a lot!

One of my friends told me to use reflection. I think this should work.

  • 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-06-17T09:29:12+00:00Added an answer on June 17, 2026 at 9:29 am

    It seems that you’re looking for an Abstract Factory.

    An Abstract Factory is a design pattern in which different types of objects can be created depending on the argument. So in this example, the factory will create a ConcreteDataADialog or a ConcreteDataBDilaog depending on the type of the data.

    Code sketch:

    class DialogFactory {
    public:
        virtual Dialog* createDialog() = 0;
    };
    
    class ADialogFactory : public DialogFactory {
    public:
        Dialog* createDialog() {
            return new ADialog();
        }
    };
    
    class BDialogFactory : public DialogFactory {
    public:
        Dialog* createDialog() {
            return new BDialog();
        }
    };
    
    class Application {
    
        Dialog* createSpecificDialog(Data data) {
            if (data.isA()) {
                return new ADialogFactory().createDialog();
            } else {
                return new BDialogFactory().createDialog();
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which is better way to use jQuery() ? I've heard that jQuery(element) doesn't ruin
I heard that in PHP there are some alternatives for the functions substr() and
I have a class WebServiceCaller that uses NSURLConnection to make asynchronous calls to a
What I'm wondering is: if having a base class, that every* other class inherits
I have an expensive function that takes and returns a small amount of data
I heard that it's possible to identify the brand of a device (or at
I heard that having @foreach inside of a view is a no-no. Meaning, the
I heard that Google can track all the static pages in a website and
I heard that you need to create images for both retina and non-retina. And
I heard that SQL is faster if table relationships are defined. Is this true?

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.