简体   繁体   English

为什么有状态/无状态小部件扩展而不实现?

[英]Why stateful/stateless widgets extends and doesn't implements?

I have this question for a job interview, and i want to know why the stateful and staless widgets, use extends and why not use implements in Flutter/Dart?我有一个求职面试的问题,我想知道为什么有状态和无状态的小部件使用扩展,为什么不在 Flutter/Dart 中使用工具?

Extends 扩展

extends is usually the go-to when you want to make a more specific version of a class.当您想要制作更具体的 class 版本时, extends通常是首选。

When you extend a class, you inherit all properties, methods, etc. If you want to override a method, you prefix the method with @override .当你扩展一个 class 时,你继承了所有的属性、方法等。如果你想覆盖一个方法,你可以在方法前面加上@override

Implements 工具

implements is when you want to make a whole new version of a class but you want to inherit the class type. implements是当您想要制作 class 的全新版本但您想要继承 class 类型时。

When you create a new implementation of a class, you are responsible for supplying everything necessary to make that class function.当您创建 class 的新实现时,您有责任提供制作 class function 所需的一切。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果 flutter 中的有状态小部件可以实现无状态小部件,为什么我们需要无状态小部件? - Why do we need stateless widgets if the same can be achieved by stateful widgets in flutter? 在无状态或有状态小部件外部使用上下文 - Using context outside stateless or stateful widgets 无状态和有状态小部件之间有什么区别? - What difference between stateless and stateful widgets? Flutter 中有状态和无状态小部件之间的关系是什么? - What is the relation between stateful and stateless widgets in Flutter? 在 Flutter 中使用 BLoC - 在有状态小部件与无状态小部件中的使用 - Using BLoC in Flutter - Usage in Stateful widgets vs Stateless Widgets 将“多个”有状态和无状态小部件存储在一个 dart 文件中。 没事吧? - Store “multiple” Stateful and Stateless Widgets in one dart file. Is it okay? 无状态还是有状态? - Stateless or Stateful? 为什么 TextEditingController 总是在 Stateful 小部件中使用? - Why is TextEditingController always used in Stateful widgets? 为什么有状态的小部件在 flutter 中定义为两个类? - Why are stateful widgets defined as two classes in flutter? 有状态与无状态的区别如何影响何时重建小部件? - How does the stateful vs. stateless distinction affect when widgets will be rebuilt?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM