Alternatives for the singleton pattern?

后端 未结 4 1019
既然无缘
既然无缘 2021-01-05 10:35

I have been a web developer for some time now using ASP.NET and C#, I want to try and increase my skills by using best practices.

I have a website. I want to load t

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-05 10:57

    Design Patterns can be amazing things. Unfortunately, the singleton seems to stick out like a sore thumb and in many cases can be considered an anti-pattern (it promotes bad practices). Bizarely, the majority of developers will only know one design pattern, and that is the singleton.

    Ideally your settings should be a member variable in a high level location, for example the application object which owns the webpages you are spawning. The pages can then ask the app for the settings, or the application can pass the settings as pages are constructed.

提交回复
热议问题