Where to store front-end data for "object calculator"

Posted by Justin Grahn on Programmers See other posts from Programmers or by Justin Grahn
Published on 2014-08-18T20:11:55Z Indexed on 2014/08/18 22:31 UTC
Read the original article Hit count: 272

Filed under:
|
|
|
|

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:

Products:

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; }
}

Recipes:

public Recipe(string n, decimal yieldAmt, Volume.Unit unit)
    {
        name = n;
        yield = new Volume(yieldAmt, unit);
        yield.ConvertUnit();
    }
    /// <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>();

MenuItems:

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)

© Programmers or respective owner

Related posts about c#

Related posts about database