Bob
Bob

Reputation: 7

Parse.com Class design

Read everything relating to this I can on SO. I am trying to develop a recipe app using Parse.com. Starting to struggle with the design of the classes however. What I need is that ability to store a recipe name, the ingredient, and their quantities.

Currently I have this:

Recipes

Ingredients

Where I am stuck is how to save a quantity for each ingredient for each recipe. From what I have seen it seems the best way to do this would be to make a third class. Let's say

RecipeDetail

This seems like a very obtuse way to handle the task but I haven't found a better way. Any input is appreciated.

Upvotes: 1

Views: 129

Answers (1)

Wain
Wain

Reputation: 119021

Yes, a third class is appropriate (other options mean creating an object with a reference and a class is a better way of doing that). I'd use a relationship from the Recipe class to the Detail class and a pointer from Detail to Ingredient. The 'relationship' from Recipe to Detail could be implemented as an array of pointers as it's unlikely that the list of ingredients will be particularly long or that you'll need to filter it.

Detail objects need to be deleted when removed from a Recipe. Ingredients aren't (or are only deleted when there are no Detail items pointing to them).

Note that you can use includeKey to shortcut some processing when you download the Detail items for a Recipe (the pointer allows you to shortcut and include the pointed to Ingredient details).

Upvotes: 0

Related Questions