Object expression
Introduction
Expression used to implement an abstract type on the fly
β Notice the signature of makeResource
: string -> System.IDisposable
.
β The backing class is hidden/transparent at the Fβ― level.
β Advantage: Upcasting is not required, compared to interface implementation in a type.
Interface singleton
We can implement a Singleton using an object expression:
Implementing several interfaces
Implementing several interfaces in an object expression is possible, but only the first interface is visible. To use the members of the other interfaces, we need to perform a downcast, which is unsafe by natureβ
π Prefer to split the object in 2.
Last updated
Was this helpful?