incorporating leppies feedback it compiles - but IMO some drawbacks I want each sub class to be forced by the compiler to define their own Uri property. Code as it is now:
[<AbstractClass>]
type UriUserControl() =
inherit UserControl()
interface IUriProvider with
member this.Uri with get() = null
Interesting enough, the class I defines which inerits from above does not show a public Uri property:
type Page2() as this =
inherit UriUserControl()
let uriStr = "/FSSilverlightApp;component/Page2.xaml"
let mutable uri = new System.Uri(uriStr, System.UriKind.Relative)
do
Application.LoadComponent(this, uri)
member public this.Uri with get () = uri
I would like to define an abstract class that inherits from UserControl and my own Interface IUriProvider, but doesn't implement it. The goal is to be able to define pages (for silverlight) that implement UserControl but also provide their own Uri's (and then stick them in a list / array and deal with them as a set:
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()
Also the Uri in the definition - I would like to implement as a property getter - and am having issues with that as well.
this does not compile
type IUriProvider =
interface
abstract member uriString: String with get;
end
3. If a class inheriting an abstract class does not define all of its function then it will be known as? Explanation: Any subclass of an abstract class must either implement all of the abstract method in the superclass or be itself declared abstract. 4.
An abstract class can inherit a class and multiple interfaces.
Java Abstract class can implement interfaces without even providing the implementation of interface methods. Java Abstract class is used to provide common method implementation to all the subclasses or to provide default implementation.
And yes, you can declare abstract class without defining an abstract method in it. Once you declare a class abstract it indicates that the class is incomplete and, you cannot instantiate it. Hence, if you want to prevent instantiation of a class directly you can declare it abstract.
Here is a way to do it:
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
Note that you have to provide an implementation of the interface (since all interface implementations in F# are explicit), but this can just refer back to abstract members in the class. Then you can subclass thusly:
type ConcreteUriUserControl() =
inherit UriUserControl()
override this.Uri = null
override this.UriString = "foo"
From a .NET point of view, you would need to at least provide an abstract implementation for the interface. But that again could proof problematic due to default interface accessibility, which would require some more glue again for an explicit implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With