How can I model complex role relationships in which only certain groups of entities can participate?

Let's say I need to simulate dinner dishes.

Food can consist of several "components":

  • (fries or rice or wedges)
  • And (one of six different drinks)
  • And (One or two of seven different sauces OR none)

Other foods may consist of:

  • (rice or salad OR)
  • AND (Garlic OR without garlic)

Further nutrition may consist of:

  • Roast

  • Just write

  • Simply...

How can I simulate this? (UML, entity-relationship, code, ... everything you can explain best)

Perhaps this helps if you know some of the tasks that I want to perform, therefore:

  • Allowing the customer to first select food and display all remaining "add-ons."
  • . , , , .

, - , "" "", "", "...", , , , n-out-of-m...

, ...

+5
5

, ... - , , . , , .., . .

..

, , ... ;).

, - . .

, , A. B. - . 1 A 1 B, A B.

... .

db , , .

, - :

group(id, name, desc) - - , , ... -

foodItem(id, name, desc) - - , ..

foodItem_group(foodIgem_Id, group_Id) - - -

combo(id, name, desc) -

combo_group(combo_Id, group_Id) - -

, - , , , , , , , -.

+1
  • , , , , Order, Component Meal s. Meal Component, .
  • A Meal "", Component s. Meal , Component .
  • " a Meal Component s" . , , - Meal , Component true, Meal (, , Component, Meal). Order Meal, , , - Component Order. .

, !

+1

Component ( ) .

Meal . , ( ). .

, "". , . . m-outof-n.

:

class Meal
{
    class MealSlot
    {
        Add(Component);
        bool DoesItMatch(vector<Component> ComponentsVector)
        {
            //Check if this Slot is filled by some element(s)
            // of ComponentsVector 
        }
        PrintSlotOptions();
        vector<Component> Options;

        // for m-of-n option, if multiple items can be chosen in this slot
        int HowManyNeededToFillIt; 
    };

    bool DoesItMatch(vector<Component> ComponentsVector)
    {
        //Check if all Slots are filled by ComponentsVector elements,
        //using Slot::DoesItMatch function
    }
    void PresentChoices()
    {
        for(i=0; i < Slots.size(); i++)
             Slots[i].PrintSlotOptions;
    }
    vector<Slot> Slots;
};

: ( ) ( )

class MealType2 : public Meal
{
    MealType2()
    {
        Slots[0].Add(Salad);
        Slots[0].Add(Rice);
        Slots[1].Add(Garlic);
        Slots[1].Add(NOTHING);
    }    
};

Order, Meal, . , Meal.PresentChoices(). , Meal.DoesItMatch.

+1

, . :

  • (, , ..).
  • : id1, id2, . :

" ", , . , , , , 50% .

" " .

0

, , ( ) Food. , : , , , , , , , , ..

: , , , , , ..

Reorganize your specific classes into all hierarchies, which they apparently want to use when you write code and tests.

sprinkle component interfaces where they make sense.

0
source

All Articles