本文介绍了有没有办法避免在不使用静态或单例的情况下覆盖新数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 几个场景。 如果两个单独的类几乎同时从同一个文件接收相同的数据,则更改数据。 场景1: 类1从调用类传递数据。 类2从同一个调用类传递相同的数据。 两个类都会更改数据并将其返回到调用类。 场景2: 类1和2加载大约在同一时间的数据。 1级保存,然后2级保存。 避免这些情况的最佳方法是什么? 我尝试过的事情: 创建一个神级处理所有数据加载,更改和保存。不是最好的方法,并试图找到更好的方法。解决方案 Couple of scenarios.If 2 separate classes receive the same data from the same file at about the same time, then change the data.Scenario 1:Class 1 is passed the data from an invoking class.Class 2 is passed the same data from the same invoking class.Both classes change the data and return it to the invoking class.Scenario 2:Classes 1 and 2 load the data at about the same time.Class 1 saves, then class 2 saves.What is the best way to avoid these situations?What I have tried:Created a god class to handle all the data loading, changing and saving. Not the best method and trying to find a better way. 解决方案 这篇关于有没有办法避免在不使用静态或单例的情况下覆盖新数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!