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.
Related
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...
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?
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.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
how do I make a class that MUST be instantiated it, or anything like that. If it is possible anyway..
You can just make a class with no static members, you know. You must instantiate a class with no static members in order to use its functionalities. Although it still inherits from Object's static members. But if you want to remove that as well, I am sorry but it is impossible.
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 8 years ago.
Improve this question
I'm using XmlManager to
do xml manipulations in several methods in a class.where I should declare XmlManager variable ?
1.locally within each method and do intialization.
2 declare at globally and initiate at the method level
As it is, in this question, there's absolutely NO difference whatsoever because there's neither performance gain nor significant design issues.
Maybe if the question is put into context there could be reason to choose one approach over the other, but as it stands now. None of the approach is better than the other one