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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:41:56+00:00 2026-06-04T14:41:56+00:00

If I have a Store class, I can write Store starbucks; Here, the variable

  • 0

If I have a Store class, I can write

Store starbucks;

Here, the variable name is the name of the object itself.

Alternatively, I can write

Store shop( "starbucks" );

where a name variable inside Store is initialized with "starbucks". Here, the variable name is generic but the object contains the specific store name.

Which is preferable, and when?

  • 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-04T14:41:57+00:00Added an answer on June 4, 2026 at 2:41 pm

    I can’t think of a real world use for Store starbucks;. Any time you wanted to add a new store you would have to write all new code and recompile. Outside of test data, for unit tests and whatnot, this should never be used.

    For similar reasons, hard coding Store shop( "starbucks" ); is also a bad idea. Again, changing instance data should not cause you to recompile your code.

    Most code that I’ve written uses a combination of user input and a data store to create instances. This is done something like Store shop; shop.load(); or more likely Store shop = storeFactory.getStore();

    In addition, I prefer to use the type of the object as the name of the object. This would make the example Store store = storeFactory.getStore();. It lowers the cognitive load of the reader, because they don’t have to remember that shop is of type Store.

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

Sidebar

Related Questions

I have a program in which I need to store a Class object into
In this scenario, I have 2 or more models: class Store(models.Model): name = models.CharField(max_length
I am attempting to store a variable length number that can have leading zeros
I have a class of students which I store into set in my cpp
I have a class in c# in that store some user messages, and return
I have a class in silverlight that I would like to store to disk.
I have small class called 'Call' and I need to store these calls into
I have the following objective C class. It is to store information on a
If I have a class with some value member that I want to store
I have a field URL countryURL; in a Country class. I want to store

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.