在项目中有很多单身人士课程是否有好的编程? [英] Is it good programming to have lots of singleton classes in a project?

查看:110
本文介绍了在项目中有很多单身人士课程是否有好的编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有什么最好的方法?


  1. 可以将其创建为静态对象。

  2. 可以创建为单例

  3. 可以创建为全局。

实现这一点的最佳设计模式是什么?


$ b $我正在考虑将所有课程都创建为单身人士,但这将创造出许多单身人士。有很多单身吗?



使用单身人士的利弊是什么?

解决方案

看看Steve Yegge关于这个的博客文章 - Singleton Consideed Stupid


I have a few classes in a project that should be created only once.

What is the best way to do that?,

  1. They can be created as static object.
  2. Can be created as singleton
  3. Can be created as global.

What is the best design pattern to implement this?

I am thinking of creating all classes as singleton, but that would create lot of singletons. Is it good programming practice to have lot of singletons?

What are the pros and cons for using singletons?

解决方案

Take a look at Steve Yegge's blog post about this - Singleton Considered Stupid

这篇关于在项目中有很多单身人士课程是否有好的编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆