Linked Questions
18 questions linked to/from Make methods that do not depend on instance fields, static?
0
votes
3
answers
4k
views
Drawback of using static method [duplicate]
For methods that never access instance variable or static variable and they act just like a function (name-spaced) and they are deterministic base on only the input arguments , I want to ask, are ...
3
votes
0
answers
610
views
Is marking members as static against object-orientated programming? [duplicate]
Me and my co-workers are having a bit of a discussion about one of the code analysis issues thrown by visual studio:
CA1822 Mark members as static The 'this' parameter (or 'Me' in Visual Basic) of '...
0
votes
0
answers
53
views
What's the value in marking static methods in a non-static class [duplicate]
I had a recent code review that gave me some slightly surprising feedback. It was in an instantiable service class that had a number of fully encapsulated private methods. In other words, methods that ...
114
votes
9
answers
187k
views
Why have private static methods?
I just wanted to clear up a question I have. What is the point of having a private static method as opposed to a normal method with private visibility?
I would have thought an advantage to having a ...
11
votes
4
answers
5k
views
What are the valid uses of static classes?
I noticed that nearly every time I see programmers using static classes in object oriented languages such as C#, they are doing it wrong. The major problems are obviously the global state and the ...
18
votes
4
answers
16k
views
Java - Is it a bad idea to have fully static classes?
I'm working on a larger solo project and right now, and I have several classes in which I do not see any reason to create an instance of.
My dice class right now, for example, stores all of its data ...
9
votes
6
answers
1k
views
Significant amount of the time, I can't think of a reason to have an object instead of a static class. Do objects have more benefits than I think? [closed]
I understand the concept of an object, and as a Java programmer I feel the OO paradigm comes rather naturally to me in practice.
However recently I found myself thinking:
Wait a second, what are ...
16
votes
1
answer
9k
views
Are we abusing static methods?
A couple of months ago I started working in a new project, and when going through the code it stroke me the amount of static methods used. Not only utility methods as collectionToCsvString(Collection&...
7
votes
4
answers
2k
views
Role and importance of static method in OOP
Background
Thinking about OOP I feel that it binds data and behavior together, taking the real world example we already have array data type which is a collection of homogeneous type and in Java we ...
3
votes
2
answers
3k
views
private method that uses no instance members - better static? [duplicate]
I have a private helper method that uses no instance variables or methods, I feel it would be less confusing if it was static (this way, it's given fewer points it can access).
I am a bit unsure if ...
7
votes
2
answers
2k
views
Static services and testability
Where is the figurative line drawn for using static services in a project? I am a coop student working and learning how to write .net MVC projects. I've been developing trying to stick to TDD. In my ...
4
votes
3
answers
464
views
What problems might arise if I didn't make a method static when I could?
I have a stateless method that takes an input, and based on that input returns an output. This method has no state so in theory it could be made static.
But let's say I don't do this. What problems ...
-1
votes
2
answers
4k
views
Is it okay to use non-static getters and setters for static variables?
Will the following design prove hard to scale in the long run:
class A {
private static volatile boolean someFlag;
public void setSomeFlag(boolean newFlag) {
someFlag = newFlag;
}...
2
votes
2
answers
555
views
Static or non-static?
For example I have these two classes:
First
public class Example
{
public Example()
{
}
public int ReturnSomething
{
return 1;
}
}
Second
public class Example
{
...
5
votes
1
answer
4k
views
Should a method always be static if it can be?
I am using Typescript in Webstorm with Angular 2 and I am frequently getting warnings that a given method can be static. Yes, these specific methods do not depend on the state of the object they are a ...