edd*_*bes 5 c# oop class-design
如果您有一个包含状态变量的类和两个需要访问它并以异步方式操作的成员类.实现这个的最佳方法是什么?
一个例子
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 state
}
Run Code Online (Sandbox Code Playgroud)
这些类是异步操作的.DeliveryMan和Supplier类都需要能够读/写状态.DeliveryMan推出餐厅的状态,供应商会听取供应商的状态.
有没有更好的方法来设计这个或以最小的耦合实现它,而不给DeliveryMan或供应商提供其所有者餐厅.