简体   繁体   English

在类外使用方法和变量

[英]Using methods and variables outside of class

在此处输入图片说明

on my flutter app, I'm using some variables and functions like this, outside of class, without dependency injection so I can access them from everywhere.在我的 flutter 应用程序中,我在类之外使用了一些像这样的变量和函数,没有依赖注入,所以我可以从任何地方访问它们。

the question is: Is this bad for performance or has any bad effect on my app?问题是:这对性能不利还是对我的应用程序有任何不利影响?

As I know this is not bad for performance because a lot of functions and variables we use in flutter like Colors class is outside the ui state class.据我所知,这对性能来说并不坏,因为我们在 Flutter 中使用的许多函数和变量(如 Colors 类)都在 ui 状态类之外。 And I all Get.* is outside the ui state class>而我都Get.*在ui状态类之外>

It is not a good practice as far as Object Oriented Programming is concerned!就面向对象编程而言,这不是一个好习惯!

Encapulating methods, and fields is necessary to make our code work as it is intended, otherwise, anyone can change anything which could lead to potential problems down the lane.封装方法和字段是使我们的代码按预期工作所必需的,否则,任何人都可以更改任何可能导致潜在问题的东西。

As Andrea Bizzotto says "Making our code easy to use as it is intended and tougher to use otherwise"正如 Andrea Bizzotto 所说:“使我们的代码易于使用,否则难以使用”

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM