Avoiding “Access to a static member of a type via a derived type”

霸气de小男生 提交于 2019-12-06 04:38:21

It seems like you want to keep the door open for extension but not for modification aka the Open Closed principle. And its a worthy goal.

My advice would be to lose the static cling - turn the function-holder classes into objects. This allows you to override (and not confuse other readers) as required - polymorphism only works with instances.

The next concern would be the need to have a global object vs passing a logger instance around. Create another type that provides access to a single instance of a logger object. (the old singleton)

e.g. ErrorLogProvider.Instance.Write(something)

PS: Freebie - easier to test these objects too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!