小编edd*_*bes的帖子

在类及其成员之间共享变量

如果您有一个包含状态变量的类和两个需要访问它并以异步方式操作的成员类.实现这个的最佳方法是什么?

一个例子

 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)

c# oop class-design

5
推荐指数
1
解决办法
214
查看次数

标签 统计

c# ×1

class-design ×1

oop ×1