2
我一直在寻找自己解决类似diamond inheritance problem东西如下(但没有任何继承!):这个设计模式有没有名字?
type I<'a> =
abstract member Foo : 'a
type a =
| A
interface I<a> with
member this.Foo = this
type b =
| B
interface I<b> with
member this.Foo = this
a
和b
通过I<_>
接口暴露,但接口的成员可以返回类型之间的共性具体基础类型的值是a
或b
,而不是必须推广到实现接口的任何类型。
例如,这将返回类型a
的值:
> (A :> I<_>).Foo;;
val it : a = A
和这个返回类型b
的值:
> (B :> I<_>).Foo;;
val it : b = B
即使值分别为向上转型到接口类型。
有没有这个名字?其他人在做这些吗?
对于那些不熟悉术语 - [钻石问题](http://en.wikipedia.org/wiki/Diamond_problem) – Oded 2010-11-11 11:07:44
本体可能? http://en.wikipedia.org/wiki/Ontology_%28information_science%29 – leppie 2010-11-11 12:04:04
@Jon - 你提到了问题介绍中的术语。我添加了一个参考。 – Oded 2010-12-22 20:01:54