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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:03:54+00:00 2026-06-12T06:03:54+00:00

What is a good way to design a class? I’m trying to create a

  • 0

What is a good way to design a class? I’m trying to create a simple chat program. I want everything the objects in the screen use to be encapsulated. I’ve created a few classes, a logging class, a message pile class (for holding the messages which have been received and sent), a textbox class, and a button class. I want the message pile, the textbox, and the button to share the same string variable, except I want it encapsulated within the classes.

I did try creating a Base class. This would hold all the data and functions common to the textbox and button classes. Those three classes would derive from Base to use its shared variable. Only when I did this the variable was not shared. Is there a way to do this? Kind of like a global variable? Only within its own class and its derived ones? Both objects of the two derived classes should be able to access the Base class object’s variables.

  • 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-12T06:03:55+00:00Added an answer on June 12, 2026 at 6:03 am

    You are mixing up classes and objects. When you have a base class with some member variable then all derived classes can (potentially) access the member variable in the base class.

    However when you instantiate the different derived classes, or one of them multiple times, then each object has a complete independent set of member variables, including the ones from the base class, because that’s exactly what an object is.

    If you want certain groups of objects to use the same “shared” variables then you could stick these shared things into a dedicated “shared” class. Then for each group of objecst that need to share these “variables”, you create an instance of this “shared” class, and pass it to all of the objects in the group.

    This is also more flexible than fiddling around with “static” class members, or whatever they are called in the language you are using, because you can have multiple of these “groups” of objects by having multiple “shared” objects and deciding exactly which “actual” objects share the same “shared” data/variables.

    Without knowing more about what’s going on it’s hard to give any more recommendations on how to design the class and object hierarchy.

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

Sidebar

Related Questions

I am trying to work out the best way to design a class that
I'm struggling to think of a good way to use linq2sql, simply I want
Anyone knows a good way to use http live streaming tools on non-Mac platforms?
Is there a good way to allow only a certain class to have read/write
Good object-oriented design says that objects should not expose their internals. Given this is
I am trying to come up with good design while implementing Store Kit. Trying
I'm trying to come up with a good design for converting a set of
I have a question regarding good design in C++. I have a class A
I was just discussing with some colleagues about Java constructors, design-patterns and good way
Is there a good way to create a form in VB6 that can easily

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.