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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:01:07+00:00 2026-05-15T16:01:07+00:00

I have a class called DataStructures where I have a set of public static

  • 0

I have a class called DataStructures where I have a set of public static data structures that store objects. To add an object to a data structures is an involved process requiring a number of checks to be carried out, processes to be remembered and data to be rearranged. In another class called Foo, I need to add objects to the data structures.
I was thinking I can do this by making a method called ObjectFeed which would take an object and the object’s label as parameters. The label would tell the method which of the data structures the object should be added to. I would also have a method called addObject which would take the object to append and the appropriate target data structure as parameters:

Public Class DataStructures
{
    public static List<obj> object1Storage = new List<obj>();
    public static List<obj> object2Storage = new List<obj>();
    ...
}

Public Class Foo
{
    public void ObjectFeed(/* PARAMETERS */)
    {
      //Code that generates an object called inspectionObject
      //inspection object has an associated enum Type
        if(objectType == Type.Type1)
        {
             addObject(inspectionObject, DataStructures.object1Storage);
        }
        if(objectType == Type.Type2)
        {
             addObject(inspectionObject, DataStructures.object2Storage);
        }
        ...
    }

    private void addObject(obj inspectionObject, List<obj> objStorage)
    {
        objStorage.Add(inspectionObject);
        //And a lot more code
    }
}

Passing a public data structure as a parameter to a method that can just as well access that data structure directly doesn’t feel correct. Is there a more clever and less intuitive way of doing this?

Edit:

In the example I originally contrived, the ObjectFeed method served no apparent purpose. I rewrote the method to look more like a method from the real world.

  • 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-15T16:01:07+00:00Added an answer on May 15, 2026 at 4:01 pm

    As pointed out in other answers:

    1. The public static Lists are bad practice
    2. Since the addObject method is the same for every data structure, it should be implemented as a data structure accessor.

    To this end, I moved the instantiation of the data structures into Foo and moved the addObject method from Foo to a new class called StorageLibrary that more accurately represents the data structure architecture.

    private class StorageLibrary 
    {
        private List<obj> storedObjects = new List<obj>();
        public void addObject(obj inspectionObject)
        {
            storedObjects.Add(inspectionObject);
            //And a lot more code
        }
    }
    
    public class Foo : StorageLibrary
    {
        //Declaration of libraries
        public static StorageLibrary storage1 = new StorageLibrary();
        public static StorageLibrary storage2 = new StorageLibrary();
        ...
    
        private void ObjectFeed(/* PARAMATERS */)
        {
            //generate objects
    
            if (objectType == Type.Type1)
            {
                storage1.addObject(inspectionObject);
            }
            if (objectType == Type.Type2)
            {
                storage2.addObject(inspectionObject);
            }
            ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a class called Store that has many Employees. My RESTful
This semester in university I have a class called Data Structures, and the professor
I have Class CustomDate and that is referred in other class called Test. public
I have a class called DatabaseHelper that wraps a DbConnection. What's the proper way
I have this class called Table: class Table { public string Name { get
I have a class called User with static function loginRequired(), which returns false if
I have a class called PriceStep . I keep a list of PriceStep objects
I have a class called Worker public class Worker : BaseEntity { public virtual
I have a class called EventConsumer which defines an event EventConsumed and a method
I have a class called Ship and a class called Lifeboat Lifeboat inherits from

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.