[英]handling more than one request
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
. 为此,我有一个名为
User
的类和一个名为Food
的类。
In the class Program
I have a field which is a list field that contains foods object. 在类
Program
我有一个字段,它是一个包含食物对象的列表字段。 In the class Program
I also have a field of user object. 在类
Program
我还有一个用户对象字段。
Now I am a bit confused. 现在我有点困惑。 The thing is if two users at the same time request order, do I need to use a list of users in my
Program
class or is the one field enough? 问题是,如果两个用户同时请求订单,我是否需要在我的
Program
类中使用一个用户列表,或者是一个字段呢? 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. 如果你想将一个以上的食物对象与一个用户联系起来,你就可以得到一个食物清单,其中包含每个用户的ID(这意味着每个用户类别中的食物清单),因此你可以将订购的食物添加到每个用户,您应该在您的程序中有一个用户列表和一个食品清单,其中包含所有带有ID的默认食品。 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)?
但是你为什么不看看使用数据库系统(如SQLite)或带有DataSet和DataTable的XML(你可以把你的食物作为XML文件,你可以很容易地将它加载到DataSet中或从一个数据集中保存它DataSet到XML文件)?
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 或者,您可以拥有一个将Food's绑定到User的特殊类
class UserFoodsMap {
private User user;
private List<Food> foods;
// ...
}
class Program {
private List<UserFoodsMap> userFoodsMap;
// ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.