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 8 years ago.
Improve this question
I'm writing a C# app, and I have a class that all it dos is to provide functionality to different class I use.
For example a class that provides clock service and more.
is there any reason to make that class a Singelton class? or Static class?
Or maybe it should not be either?
If your class needs to keep an inner state it should be a Singelton, if it doesn't simply make it static!
Inner states could be:
A file reference
A user preference
Any kind of history
If it is merely a collection of functions etc.. like Math, KISS (keep it simply Static)!
Related
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 1 year ago.
Improve this question
I would like to initialize a record from a class. For example, I read in a bunch of objects from a ReST call. These objects should be immutable, so the record type would fit the bill nicely, but I want to write a bunch of code to convert them to records.
Suggestions?
I'm assuming you don't have write access to the API that creates the classes? Because, honestly, it would probably better just to rewrite that.
There are libraries available such as AutoMapper (https://github.com/AutoMapper/AutoMapper).
Beyond that, there are no casts you can use, and unless the classes are highly regular, you need to write custom conversions for each class.
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
I've read Clean Code by R.C. Martin and I'm trying to adopt his suggestions about clean code as broadly as possible.
But I'm not sure how to name related classes.
Let's say I have a class named TreeDirectoryList.
I want to cut implementation of this class into many smaller classes.
Let's say I'll create a class named ParentIndexStack.
ParentIndexStack will implement functionality very dependent on TreeDirectoryList, so it's very not probable that this implementation of ParentIndexStack will be useful with any other class in the future.
But the name of ParentIndexStack is very generic, it's possible, that I'll need another class with the same name, within the same project.
So I thought I'll name ParentIndexStack more precise, like TDLParentIndexStack (prefix TDL is from TreeDirectoryList).
Would it be correct ?
I'll end with many classes starting with TDLxxxxx.
One option is to put that set of classes in their own namespace. Then you can have simple, concise names that still communicate the full meaning of the class through the namespace context.
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.
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 6 years ago.
Improve this question
I have a question about c#, but I have no idea how to google it or something. So I''m going to ask it here:
In c#, you have things like "Timer.Interval". Is it possible to make something similair like that myself?
For example, I have this void called "writeLine". I have this boolean, UseDelay, so that my function waits a while before writing things down. I want that boolean to become accessible as "writeLine.UseDelay = false" or "if (writeLine.UseDelay == false)" etc. I'm just curious.
Thanks in advance!
What you're talking about is actually a Property of a class. There are ofcourse ways you can implement your own properties (actually just public variables inside the structure of your class) and your own methods (for example, take a look here). If you're interested in further constructions and options, there is plenty of information on the web.
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.