如果您有一个包含状态变量的类和两个需要访问它并以异步方式操作的成员类.实现这个的最佳方法是什么?
一个例子
public enum RestaurantState
{
BREAKFAST,
LUNCH,
DINNER
}
public class Restaurant
{
//Below need access to state
private DeliveryMan pizzaDriver ;
private Supplier butcherShop ;
internal RestaurantState state ;
}
public DeliveryMan
{
//Uses a System.Timers.Timer
//Wakes up and does work every a minute
//Needs to inform state of restaurant
}
public Supplier
{
//Waits and listens for requests to accept deliveries
//If suppliers run out we need to change the restaurant state based on our own current …Run Code Online (Sandbox Code Playgroud)