Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个相对较小的项目,我使用的是 3 层架构。现在我正在考虑如何将一些函数拆分到不同的数据类中。
例如,我有一个 User 类和一个 Group 类。我的 User 类有一个 User.GetGroups 函数,我的 Group 类有一个 Group.GetUsers 函数。我会将第一个放在 UserData 类中作为 UserData.GetGroups 还是放在 GroupData.GetGroupsForUser 中,或者可能是一个完全独立的 UserGoupData 类?
为什么不执行您的两个建议?关于 GroupData.GetGroupsForUser:仅“ForUser”这句话就让我想“如果它是给用户的,为什么不把它放在用户对象上呢?”
我只会做 User.Groups 和 Group.Users。我认为你的两个例子都有道理。