开发者

handling more than one request

开发者 https://www.devze.com 2023-01-13 18:05 出处:网络
I am writing an ordering system. In this program, the user can request food. For this purpose I have a class named User and a class named Food.

I am writing an ordering system.

In this program, the user can request food. For this purpose I have a class named User and a class named Food.

In the class Program I have a field which is a list field that contains foods object. In the class Program I also have a field of user object.

Now I am a bit confused. The thing is if two users at the same time reques开发者_Python百科t order, do I need to use a list of users in my Program class or is the one field enough? Or do I need to use threading.

The way I have written the app, it just handles one request at the time. So what about further requests? What changes do I need to apply so it handles users' requests?

I am not using any database at the moment (which I am not that much familiar with)

class User {
  private string name;
  private string address;
  // ...
}

class Food {
  private string name;
  private int id;
  // ...
}

class Program {
  private User user;
  private List<Food> foods;
  // ...
}


If you want to associate a more than one food objects with a user, you could have a list of foods with their IDs for each user (that means a list of foods in every user class), so you could add the ordered food items to each user and you should have a users list in your program and a food list containing all the default food items with their IDs. But why don't you take a look in making it with a DB system (like SQLite) or XML with DataSet and DataTable (you could have your foods as an XML file and you could easily load it into a DataSet or save it from a DataSet to an XML file)?


A list of Foods is maintained for each User. You can have a Dictionary here.

class Program {
    private Dictionary<User, List<Food>> userFoodsMap;
    // ...
}

Or, you can have a special class that binds Food's to User

class UserFoodsMap {
    private User user;
    private List<Food> foods;
    // ...
}

class Program {
    private List<UserFoodsMap> userFoodsMap;
    // ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消