dotnet / dotnet/docs

What Interface Methods are useful for?

Open
#30,663 2 comments 0 reactions 0 assignees View on GitHub
advanced-concepts/subsvc dotnet-csharp/svc
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
15h 21m
Merged PRs (30d)
370

Description

1 Forced cast:
![image](https://user-images.githubusercontent.com/6546735/184405833-f8ee95cd-1ac5-4e90-a3f4-415462c119a8.png)

Nonsense. Who inherits interface should be able to call. It has to implement every member of base interface so it can safely call that method without that extra cast

2.Parametrization
This is even more ridiculous
![image](https://user-images.githubusercontent.com/6546735/184406185-11f8715b-997c-4f8e-ae5b-e88fa0e2d02b.png)

You have to write a ton of extra code.
Just let Roslyn or your boilerplate code generation to handle the fact that variables need to be initialized and used as parameters.
It should really be like this:
![image](https://user-images.githubusercontent.com/6546735/184406429-0f7fe421-5303-478f-acda-45504515256c.png)

3. The use of access modifiers here doesn't make any sense?
![image](https://user-images.githubusercontent.com/6546735/184406534-51692858-6921-4ea4-a037-84e450c8f86a.png)

Ehm no????
Interface require you to implement methods.
You could just let people override it with their own implementation. Protected is not needed?????

When one overrides base interface method it will call the inheriting class method, else the interface one.

This has to be the most useless thing ever

Calling the static method through the interface it's the same exact thing as doing any other utility static class.....
You can't do anything with it as you have to give an instance to use properties inside it and interface can't have any so everything is passed as a parameter and therefore useless. Any static class can do the same stuff without this convolute interfaces workaround

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: 54cebe71-9575-ed30-b6b8-1f6222061961
* Version Independent ID: ecda34c3-a5b7-8b8c-baa4-4ea741478e5f
* Content: [Safely update interfaces using default interface methods in C#](https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/default-interface-methods-versions)
* Content Source: [docs/csharp/whats-new/tutorials/default-interface-methods-versions.md](https://github.com/dotnet/docs/blob/main/docs/csharp/whats-new/tutorials/default-interface-methods-versions.md)
* Product: **dotnet-csharp**
* Technology: **csharp-advanced-concepts**
* GitHub Login: @BillWagner
* Microsoft Alias: **wiwagn**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.