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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:04:28+00:00 2026-05-13T10:04:28+00:00

Greetings, I’m a beginner to OO and programming and I have the following situation:

  • 0

Greetings,

I’m a beginner to OO and programming and I have the following situation:

I have a set of const values and enums that several of the classes I implement share.

These classes are independent i.e. other than sharing these values, they do not interact with each other, so inheriting them won’t work.

I was wondering; If I create an empty class with just these consts and enums and then declare an object of these class in each class then i could use these values like:

globals.enum.enummember?

Is this sound programming or is there a better way of doing this?

Thanks for your time.

  • 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-13T10:04:28+00:00Added an answer on May 13, 2026 at 10:04 am

    The best practice is to simply declare the enums alongside with your classes, not nested in a class. Actually, nested types are usually a bad idea, unless they are private. There are exceptions, of course, but for the most part you’re better without nesting.

    Constants have to be defined in a class, but you don’t need to instantiate an object of the class to use them. Also they can be public, so you don’t need to inherit anything. If you think about it hard enough, you should be able to figure out a good name for the class that contains these constants.

    Practice shows that constants and enums rarely are simply global. Most of the time they are closely coupled with one or few classes. You should then define these constants as a part of the appropriate class and put enums in the same namespace as the class using them.

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

Sidebar

Related Questions

Greetings, inside one of the column I have values like the following: 9-7 9-18
Greetings! I have a Repeater control that's using an XmlDataSource control. <asp:FormView id=myFormView runat=server
Greetings, I have an asp.net mvc application. I have some links that corresponds to
Greetings, I have a jqueryui autocomplete input that uses an ajax call to populate
Greetings! I have an issue here that i can't find. I am getting a
Greetings: I have put together a RESTful web service in .NET 3.5 that takes
Greetings, I have three TS variables resembling something like the following: data <- read.csv(...)
Greetings! I'm trying to have a UIWebView controlled from generated events. Is there a
Greetings, I have a form where employees enter comments in a multiline textbox with
greetings all i have a domain class named car and i have an object

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.