When to use abstract class over an interface with default implementations? [closed] - c#

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
C# 8 adds the option for default method implementation in interfaces, meaning a method CAN be defined in the interface.
In a situation when I DON'T need a default constructor, nor inherited fields in the derived classes, what should I default to: An interface with a default implementation, or the old-school way of an abstract class?
Is there a convention for styling for this case?

Related

Can anyone explain what is the default interface implementation in C# 8.0? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I’m quite new to C# 8.0 and I want to know what is the default interface implementation?
Default implementations is a feature in C# 8.0 that an interface member can now be specified with a code body, and if an implementing class or struct does not provide an implementation of that member, no error occurs. Instead, the default implementation is used.
Read more here: Default Interface Implementation

why is Read7BitEncodedInt(); in BinaryReader protected? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I know you can easily create a wrapper around BinaryReader and expose Read7BitEncodedInt
But I'm just curious why the creators chose to not make it public
Is there a logic reason for it?
My guess is that this is internal implementation detail and isn't required to effectively use the BinaryReader. I wonder the opposite, why isn't it private? Presumably, there is a subclass out there that needs to use it or overwrite the implementation...

Define constants needed in more than one class [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
In my smart client solution, I have a Project folder with:
IProjectView.cs
*ProjectView*
ProjectView.cs
ProjectView.Designer.cs
ProjectView.GeneratedCode.cs
ProjectView.resx
ProjectViewPresenter.cs
I want to define some constants for user by ProjectView.cs and ProjectViewPresenter.cs. Both of these classes implement IProjectView.cs, so were I back in Java, I'd put them there. If this were C++, I'd create a class ProjectConstants.cs and have the classes inherit it, but C# doesn't allow multiple inheritance.
How do I do this?
Can having a Read-Only Property in your interface solve your problem?
string MyReadOnlyProperty { get; }
I have no clue if this is very performance-wise compared to constant thought.

Why is KeyValueConfigurationCollection not sealed? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
KeyValueConfigurationCollection is not sealed.
All other configuration collections are sealed for both netframework and corefx:
NameValueConfigurationCollection, ConnectionStringSettingsCollection, ProviderSettingsCollection, SchemeSettingElementCollection.
There are some subclasses of KeyValueConfigurationCollection in corefx repository, but only for test purposes.
Is KeyValueConfigurationCollection not sealed only for tests or there are other design reasons for that?
A class is unsealed so others can inherit from it. So presumably it was left unsealed because it was thought that people would want to subclass it. The fact that it is subclassed for test cases, indicates that it was the right thing to do. If subclassing it can help with testing it (or something else) then there are probably other scenarios where it is beneficial.

is it possible to implement dynamic polymorphism using interface in C#.net [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
is it possible to implement dynamic polymorphism using interface in C#.net. Dynamic polymorphism can be done only by using abstract class ?
In the interface you cannot specify the accessibility of the functions, while in the abstract classes you specify exactly what your functions are and you can only override them. If you can use interfaces to solve your problem you don't need to implement dynamic polymorphism. You can read more about what I'm talking here: https://msdn.microsoft.com/en-us/library/ebca9ah3.aspx

Categories

Resources