是否有一个识别的模式为无用的对象实现一个接口? [英] Is there a recognized pattern for useless objects that implement an interface?
问题描述
在我开发的应用程序中,我经常发现使用默认实现NullFoo或类似的实现接口IFoo最好有一个无用的实现,而不是根本不传递一个对象。
我的问题是在文档化或解释架构时应该如何参考这种做法?是否有公认的名称或GoF / Fowler设计模式?
此模式通常被称为NullObject:< a href =http://en.wikipedia.org/wiki/Null_Object_pattern =noreferrer> http://en.wikipedia.org/wiki/Null_Object_pattern
For example, (although it's not an interface) the Stream class in .NET has an implementation provided by Stream.Null which simply discards the data. PowerShell has Out-Null.
In applications I've developed, I've often found it useful to implement an interface IFoo with a default implementation NullFoo or similar when it is preferable to have a useless implementation rather than not passing an object at all.
My question is how should I refer to this practice in documenting or explaining an architecture? Is there a recognized name or GoF/Fowler design pattern for this?
This pattern is often refered as "NullObject" : http://en.wikipedia.org/wiki/Null_Object_pattern
这篇关于是否有一个识别的模式为无用的对象实现一个接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!