Structure of orders in restaurant

2019-08-30 09:28发布

What would be the best way to structure orders for a restaurant (available languages are php and javascript)? Since there are multiple tables (the ones you keep things on...), I thought of using objects in javascript. But I am quite new to javascript and absolutely new to OOP, so I'm not sure whether this is the best solution, and whether my design is actually ok. Here is what I have come up with:

var order = {
    id: 0,
    table: 0,
    number_of_items: 0,
    item: {
        name: "",
        quantity: 0,
        unit_price: 0
    },
    total: 0
};

9条回答
时光不老,我们不散
2楼-- · 2019-08-30 09:56

It really depends how you will write your program. If you will not use AJAX, you dont need any javascript structure. I do not use the syntax you use (I prefer building classes in functions) but, item should be plural and must be an array. Remember this, although it seem nice to have some OO stuff, if it adds to complexity it should be avoided. Although we use AJAX in our applications, we do not have Javascript representation of objects, we use only PHP classes and Javascript deals with XML data it gets. Only classes we have in JS are widgets.

查看更多
Deceive 欺骗
3楼-- · 2019-08-30 10:00

I think an identification of objects needs to take place prior to any coding (resist the urge to code). Some objects include (some already identified):

  • table
  • waiter
  • item (pre-defined list of standard menu items along with ability for daily specials and special order)
  • order - grouping of items - could be more than one order per table, a client can have multiple waiters and tables if they move from bar to table, each of those transitions could be handled by paying or transferring the items

You also need a workflow built in (new order, fulfilled, update, closed and paid)...

查看更多
smile是对你的礼貌
4楼-- · 2019-08-30 10:07

You don't need the number_of_items as you can get that from the item array, so you will want to have an array of items.

var order = {
    id: 0,
    table: 0,
    items: []
};

Ideally you may want to have another class for item and just put a list of them in your items array.

It would look like:

items = [{name: "", quantity: 0, unit_price: 0}, {...}, {...}]

You can get the total by looping through the array and do the math.

Unless the math is overly complex I tend to prefer to not have derivable values stored in the object, but that is just what I do.

查看更多
登录 后发表回答