I recently have completed a language library that acts as a giant filter for food items, and flows a bit like this :Products -> Recipes -> MenuItems -> Meals and finally, upon submission, creates an Order.

I have also completed a database structure that stores all the pertinent information to each class, and seems to fit my needs.

The issue I'm having is linking the two. I imagined all of the information being local to each instance of the product, where there exists one backend user who edits and manipulates data, and multiple front end users who select their Meal(s) to create an Order. Ideally, all of the front end users would have all of this information stored locally within the library, and would update the library on startup from a database.

How should I go about storing the data so that I can load it into the library every time the user opens the application? Do I package a database onboard and just load and populate every time?

The only method I can currently conceive of doing this, even if I only have 500 possible Product objects, would require me to foreach the list for every Product that I need to match to a Recipe and so on and so forth every time I relaunch the program, which seems like a lot of wasteful loading.

Here is a general flow of my architecture:


public class Product : IPortionable
    public Product(string n, uint pNumber = 0)
        name = n;
        productNumber = pNumber;

    public string name { get; set; }
    public uint productNumber { get; set; }


public Recipe(string n, decimal yieldAmt, Volume.Unit unit)
        name = n;
        yield = new Volume(yieldAmt, unit);
    /// <summary>
    /// Creates a new ingredient object
    /// </summary>
    /// <param name="n">Name</param>
    /// <param name="yieldAmt">Recipe Yield</param>
    /// <param name="unit">Unit of Yield</param>
    public Recipe(string n, decimal yieldAmt, Weight.Unit unit)
        name = n;
        yield = new Weight(yieldAmt, unit);

    public Recipe(Recipe r)
        name = r.name;
        yield = r.yield;
        ingredients = r.ingredients;

    public string name { get; set; }
    public IMeasure yield;

    public Dictionary<IPortionable, IMeasure> ingredients = new Dictionary<IPortionable,IMeasure>();


public abstract class MenuItem : IScalable
    public static string title = null;

    public string name { get; set; }
    public decimal maxPortionSize { get; set; }
    public decimal minPortionSize { get; set; }

    public Dictionary<IPortionable, IMeasure> ingredients = new Dictionary<IPortionable, IMeasure>();

and Meal:

public class Meal
    public Meal(int guests)
        guestCount = guests;

    public int guestCount { get; private set; }

    //TODO: Make a new MainCourse class that holds pasta and Entree
    public Dictionary<string, int> counts = new Dictionary<string, int>(){
       {MainCourse.title, 0},
       {Side.title , 0},
       {Appetizer.title, 0}

    public List<MenuItem> items = new List<MenuItem>();

The Database just stores and links each of these basic names and amounts together usings ID's (RecipeID, ProductID and MenuItemID)

  • I am considering this question: is it really necessary to have all data loaded from database to perform the particular order calculation? Does the front-end user need to see MenuItems, Recipes or Products - he selects only from Meals as you wrote, or not? Aug 18 '14 at 20:42
  • They select only from MenuItems, which when added together create a Meal. This is what I am curious about too, as realistically the front-end user only needs to see a list of MenuItems. Do I then reverse create Products and Recipes when creating my Meal using DB links? Aug 18 '14 at 20:48
  • And do you plan to distribute this app to client devices or is it a web app? I suppose that the client needs to see at least the final calculated price or some other calculated information. It seems to me now that I would load data from DB allways for one particular calculation only. Aug 18 '14 at 20:54
  • Cost is currently devised using another application. This is used solely for meal preparation units and purchasing guides. This could be a web app or a desktop application, though I intend to start it as a Desktop application only. Using the suggested method then I would simply be using LINQ? Aug 18 '14 at 21:01
  • How often and how much do you expect Products -> Recipes -> MenuItems data to change? If it is changed quite seldom you can also package data updates in your application update. Aug 18 '14 at 21:05

There are certainly various strategies to solve this problem.

One possible way is to do it client-server.

Use case model: Use case

The front-end app will be desktop app installed on user's device without its own database. When front-end user needs to select from menuitems it will invoke GetMenuItems method on the server and will receive all the menu items (without links to Products and Recipes).

Then the front-end user creates collection of Meals form available MenuItems. When he finishes with it, he posts his choice to server by invoking MakeOrder method with Meals collection as a parameter.

The server will create only instances of objects (of classes Product, Recipe, MenuItem) that are necessary to complete requested calculation. I suppose that from given MenuItem you can select only relevant Recipes and relevat Rroducts. Only optionally server can cache all Product, Recipe, MenuItem instances in memory.

Then the result of the calculation will be then presented on client.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.