Interface 定义一个抽象类,该类继承一个接口,但不实现它
结合Leppie的反馈,它进行编译——但我希望编译器强制每个子类定义它们自己的Uri属性,这有一些缺点。现在的代码:Interface 定义一个抽象类,该类继承一个接口,但不实现它,interface,f#,abstract-class,Interface,F#,Abstract Class,结合Leppie的反馈,它进行编译——但我希望编译器强制每个子类定义它们自己的Uri属性,这有一些缺点。现在的代码: [<AbstractClass>] type UriUserControl() = inherit UserControl() interface IUriProvider with member this.Uri with get() = null 我想定义一个从UserControl和我自己的接口IUriProvider继承
[<AbstractClass>]
type UriUserControl() =
inherit UserControl()
interface IUriProvider with
member this.Uri with get() = null
我想定义一个从UserControl和我自己的接口IUriProvider继承的抽象类,但不实现它。目标是能够为silverlight定义页面,这些页面实现UserControl,但也提供自己的Uri,然后将它们粘贴到列表/数组中并作为一个集合处理:
type IUriProvider =
interface
abstract member uriString: String ;
abstract member Uri : unit -> System.Uri ;
end
[<AbstractClass>]
type UriUserControl() as this =
inherit IUriProvider with
abstract member uriString: String ;
inherit UserControl()
从.NET的角度来看,您至少需要为接口提供一个抽象实现。但是,由于默认的接口可访问性,这可能再次证明是有问题的,因为显式实现需要更多的胶水 以下是一种方法:
type IUriProvider =
abstract member UriString: string
abstract member Uri : System.Uri
[<AbstractClass>]
type UriUserControl() as this =
inherit System.Windows.Controls.UserControl()
abstract member Uri : System.Uri
abstract member UriString : string
interface IUriProvider with
member x.Uri = this.Uri
member x.UriString = this.UriString
不幸的是,我不太清楚F是否能提供更多帮助,但我希望很快能了解更多:
type IUriProvider =
interface
abstract member uriString: String with get;
end
type IUriProvider =
abstract member UriString: string
abstract member Uri : System.Uri
[<AbstractClass>]
type UriUserControl() as this =
inherit System.Windows.Controls.UserControl()
abstract member Uri : System.Uri
abstract member UriString : string
interface IUriProvider with
member x.Uri = this.Uri
member x.UriString = this.UriString
type ConcreteUriUserControl() =
inherit UriUserControl()
override this.Uri = null
override this.UriString = "foo"