对于后端数据库/存储库到状态类来说,这是一个很好的状态管理选项吗?
自定义后端状态管理问题。我认为这有点主观,但我确实想要客观的一面,例如,为什么这可能是坏的或好的,这是否可以比任何其他状态管理选项(例如 Riverpod)更简单、更好,至少对于一小部分我的后端。
我正在为我的后端设计一个状态管理,并且希望避免提供者和实例化的冗长。我的前端代码很好地利用了Riverpod,这不是一个涉及前端的问题。
这个状态管理如何寻找后端代码?我会遇到任何类型的问题吗?:
void main() {
// Set name
DatabaseRepository.createName('John');
print(State.getName());
// Update database & state, name
DatabaseRepository.createName('Terry');
print(State.getName());
}
abstract class State {
static String? _name;
static void getNameFromDatabase(String name) {
_name = name;
}
static String getName() => _name!;
}
abstract class DatabaseRepository {
static String? _name;
static void createName(String name) {
_name = name;
State.getNameFromDatabase(_name!);
}
}
Custom backend state management question. I think this is a little subjective but I do want an objective side to this such as, why coud this be bad, or good and can this be simpler and better than any other state management option such as riverpod, at least for a small part of my backend.
I'm designing a state management for my backend and want to avoid the verboseness of Providers and the instantiations also. My front end code utilizes Riverpod beautifully, this is not a question referring to front end.
How does this state management look for backend code? Will I encounter any kinds of issues?:
void main() {
// Set name
DatabaseRepository.createName('John');
print(State.getName());
// Update database & state, name
DatabaseRepository.createName('Terry');
print(State.getName());
}
abstract class State {
static String? _name;
static void getNameFromDatabase(String name) {
_name = name;
}
static String getName() => _name!;
}
abstract class DatabaseRepository {
static String? _name;
static void createName(String name) {
_name = name;
State.getNameFromDatabase(_name!);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
后端没有状态。在后端,最重要的是代码以正确的顺序执行。
如果没有什么可更新的,那么一开始就有一个状态有什么意义呢?
如果有需要更新的内容,您将在代码中的何处更新它?
There is no state for backend. In the backend, all that matters that the code is executed in the right order.
If there is nothing to update, what is the point of having a state to begin with?
If there is something to update, where in your code are you updating it?