Monotouch - 使用应用程序类作为公共对象的存储

发布于 2024-10-05 23:03:39 字数 302 浏览 0 评论 0原文

为了在视图和对象之间进行通信持久信息,例如用户名和显示字体大小的选择,将它们放在应用程序对象上是否被认为是良好的形式,或者将它们放入静态单例中是否更有效?

例如:

public class Application
    {
        static void Main (string[] args)
        {
            UIApplication.Main (args);
        }

        public static Username {get;set;}
    }

To communicate between views and objects persistant information, for example the username and choice of font size for display, is it considered good form to put these onto the Application object, or is it more efficient to put them into static singletons?

For example:

public class Application
    {
        static void Main (string[] args)
        {
            UIApplication.Main (args);
        }

        public static Username {get;set;}
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

第几種人 2024-10-12 23:03:39

我认为将静态对象放入应用程序与单例与静态类之间在性能方面没有任何差异。

对于颜色和字体之类的东西,我通常更喜欢创建静态类来保存每种类型的对象,因此例如我通常这样写:

public static class Colors {
    public static Color ToolbarColor = Color.Black;
    ..
}

这使得更改整个应用程序的颜色变得更容易,而不必到处搜索。我对字体、图像等也做了同样的事情。

I don't think there's any difference performance-wise between putting static objects into the Application vs singletons vs static classes.

For things like Colors and fonts, I usually prefer to create static classes to hold each type of object, so for example I usually write this:

public static class Colors {
    public static Color ToolbarColor = Color.Black;
    ..
}

This makes it easier to change colors around the entire app without having to be searching around everywhere. I do the same thing for fonts, images, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文