C
C#2y ago
spicedruid

❔ Make interface deriving from another interface have a sealed implementation of a function

...so that you dont have to write the same code for every child interface. details are in pastebin: https://pastebin.com/UwLuyRWA
Pastebin
//Command systempublic interface ICommand{ public abstract void ...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
9 Replies
spicedruid
spicedruidOP2y ago
I am using this in Unity by the way, Which I dont think uses the most up-to-date version of C#
Jothay
Jothay2y ago
It should be available in C# 8 Not sure about the sealed part
Jothay
Jothay2y ago
Mads Torgersen
.NET Blog
Default implementations in interfaces - .NET Blog
Default implementations in interfaces With last week’s posts Announcing .NET Core 3.0 Preview 5 and Visual Studio 2019 version 16.1 Preview 3, the last major feature of C# 8.0 is now available in preview. A big impediment to software evolution has been the fact that you couldn’t add new members to a public interface.
spicedruid
spicedruidOP2y ago
just following what is written here doesnt seem to work, just using public void for the child class makes the compiler tell me that I need to use the new keyword
Jothay
Jothay2y ago
If you don't put the one that has the default implementation onto the class that is implementing the interface, does it complain that there is no implementation?
spicedruid
spicedruidOP2y ago
ah, I see. Thats a bit confusing I dont need to use new, sealed or override at all, I just needed to use ICommand.Process in the child interface to override it
Jothay
Jothay2y ago
The learn page that is linked at the end of the article shows a pattern to extend/override the default implementation
spicedruid
spicedruidOP2y ago
ok well thanks for the help there I will have a look at that
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?