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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:28:52+00:00 2026-05-31T17:28:52+00:00

I have a problem trying to design some generic storage.. Basically I have the

  • 0

I have a problem trying to design some generic storage..

Basically I have the following 4 objects

Pallet
Box
Parcel
Item

The top 3 are all containers, which can contain anything lower in the heirarchy than itself.
Initially, it was forced so that Pallets contain boxes, boxes contain parcels, parcels contain items.
But now I want it so some of the ‘middle’ containers can be skipped:
EG, Pallets contain Parcels which contain Items (no cartons)
EG2, Pallets contain Items (no Cartons or items).

At the moment I have a database table for each of these objects.
But it’s becoming messy to design a way to keep track of everything.

In Code, I’m presented with other problems, eg to print the contents of a pallet, initially would be:

class Pallet : List<Box> {}
class Box : List<Parcel> {}
class Parcel : List<Item> {}
class Item {}


class Pallet : List<Box>
{
    void Print()
    { 
        foreach (Box b in this)
            foreach (Parcel p in b)
                foreach (Item i in p)
                    //Print
    }
}

But now since I dont know what will be inside, I’m not sure how to go about it.

I’m hoping someone can give me advice on designing a good data structure or method of storing everything in a good and efficient manner.
I could do something like:

class Pallet : List<T>
{
    void Print()
    {
        if (this[0] is Box)
            //do this
        if (this[0] is Parcel)
            //do this, etc
    }
}

But it seems horribly messy.

I hope you can see what I am trying to do.

  • 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-31T17:28:53+00:00Added an answer on May 31, 2026 at 5:28 pm

    Why can’t you simply derive each container from the exact same base class? Then you could have something like the following:

    public abstract class Container
    {
        public abstract void Print();
    
        public List<Container> Contents { get; set; }
    }
    
    public class Box : Container
    {
        public override void Print() 
        {
            foreach (Container c in Contents)
                Console.WriteLine("I am a {0}", c.ToString());
        }
    
    }
    

    This means that any container can contain a number of other containers. Of course you will need to implement some logic to control this, you don’t want a Box containing too many Parcels, but a Box could contain another box provided it was smaller. Now you would say “but Item would have to also inherit from COntainer to be contained within a Box”, and you would be right, but you can still use inheritance and a simple small change:

    public interface IContainable { }
    
    public abstract class Container
    {
        public virtual void Print() 
        {
            foreach (IContainable c in Contents)
                Console.WriteLine("I am a {0}", c.ToString());
        }
    
        public List<IContainable> Contents { get; set; }
    }
    
    public class Pallet : Container {  }
    
    public class Box : Container, IContainable {  }
    
    public class Item : IContainable { }
    

    Using this approach means a Pallet can contain things, but it cannot be contained. An Item can be contained but isn’t a container.

    You can also store all your containers in the same self-referencing database table – they don’t need to be separated out. Each contained item can simply have a foriegn key back to another entry in the same table that is its container.

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

Sidebar

Related Questions

I am trying to design an mail system. I have stuttered on the problem
I need to abstract some behavioural code and have a problem trying to reference
I have just hit a confusing problem when trying to compile some code using
I have a problem trying to edit. I work with Areas for better management
I have a problem trying to hide .php extension from the url I have
I implemented the table sorter yesterday and i have a problem trying to change
I have a problem when trying to execute this update statement (below) using C#
I have this problem when trying to run hello world program using android SDK.
I have a problem when trying to send a POST request. The sending method
Hey all, i have a problem with trying to get 2 forms to close

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.