The tag has no usage guidance.

learn more… | top users | synonyms

32
votes
7answers
20k 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 ...
16
votes
3answers
12k views

Why prefer non-static inner classes over static ones?

This question is about whether to make an inner class in Java static or not. I searched around here and on StackOverflow, but couldn't really find any questions regarding the design implications of ...
14
votes
4answers
3k views

Make methods that do not depend on instance fields, static?

Recently I started programming in Groovy for a integration testing framework, for a Java project. I use Intellij IDEA with Groovy plug-in and I am surprised to see as a warning for all the methods ...
7
votes
1answer
1k views

static globals and anonymous namespaces in C++

Why did C++ make any distinction between static globals (internal linkage) and symbols in an unnamed namespace (external linkage, but no way to refer to it from outside anyway), when introducing the ...
6
votes
7answers
916 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 ...
6
votes
2answers
293 views

Static console object or dependency injection?

For a current project I have created a Console class which wraps up C++'s usual cout, writes output to a file or uses Console::WriteLine depending on the environment. Currently I've setup my code base ...
5
votes
1answer
444 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 ...
4
votes
3answers
3k views

Why shouldn't an object reference have access to a static member in C#

Context of my question: I am reading C#. Trying to understand Static keyword. I understand that when Static is applied to a member of a class, it can only be modified by the class and not the class ...
4
votes
4answers
5k views

Static vs. non-static? (with non-OOP functions)

Although this question has come up before, mine is different because it is not supposed to cover anything OOP but only plain (ANSI) C. Especially in open-source software, I usually encounter a ...
4
votes
2answers
3k views

Best approach for multilingual Java Enum

I'm running into issues with an approach I am taking and am now wondering if I just started down the wrong path and should rethink my approach. Here is what I attempting. I would like to use an Enum ...
4
votes
3answers
4k views

When to use a Singleton and when to use a static class [duplicate]

I've searched about this here and on StackOverflow and found some differences between the two. But I'm still not sure in what cases one would prefer a Singleton, and in what cases one would choose to ...
4
votes
3answers
452 views

Creating a Java project without using any objects and just calling static methods on input?

I'm creating a program which takes a document, extracts it, and then moves this into a database. I've done most of this now and I've realised that I haven't made any instances of classes I've made (I ...
3
votes
2answers
333 views

How isolated are static variables?

If I have a public class SomeClass { public static final HashMap hashmap = new HashMap(); } and then I have five different classes with main(String[] args) methods, that I will run. when they ...
3
votes
1answer
178 views

How to design similar purpose static methods

I know that you cannot override static functions, but for what I'm looking to do, it seems like the logical way to design my class. I have a method that is associated with my abstract class, that i ...
2
votes
4answers
240 views

Are static global variables as bad as global variables? How to avoid using them?

In general, I know that global variables are bad and their should be avoided. Are static global variables equally bad? In all my projects, I have heavily relied on static global variables. From ...
2
votes
0answers
428 views

Use a global variable, a singleton, or something else

Preface: I am working in PHP (Abandon hope all ye who enter here). Background: There exists a large set of global functions in PHP, a number of which are miscellaneous system calls, like sleep (and ...
1
vote
3answers
6k views

Why static methods can't call non-static methods directly? [duplicate]

I don't understand why most programming language don't allow developers/users to call non-static method from static method directly? What is the reason behind it? p.s. I know, you can create object ...
1
vote
3answers
181 views

Should class with only static data need to be instantiated?

I have two classes. 1. Node 2. MixedStateManager Node class: Node class maintains the state of nodes in the system. One such data is state. public class Node { private int state; ...
1
vote
1answer
276 views

Why VB local variables can be 'static', not 'shared'?

In Visual Basic .NET, I can see different keyword for the same(?) concept: • methods Shared • properties Shared • class-level variables Shared BUT • local variables ...
1
vote
1answer
80 views

Manual reload of Java classes static block

I have a static block which fetches data from database. This data is then being used by instance method. Since static block will be loaded once I fear that the data won't change in its lifetime. How ...
1
vote
3answers
393 views

Why are inheritance and interfaces restricted to instance members?

Disclaimer: I think the rules are almost the same in most OO languages, but since I'm most familiar with C# I'll be relating to this specific language. I think that the use of attributes and ...
1
vote
1answer
98 views

Proper MVC practice for a hierarchy of elements

I am trying to develop my first major MVC application, and as such I am new to doing this on a large scale. I've read as much as I can online and am continuously striving for making my code as clean ...
1
vote
1answer
507 views

How to store/deal with data available to other classes

I'm writing a CAD program. Let's say I have in input class, this class reads various data from a text file and creates lots of lists/dictionaries and .... These data need to be accessed by other ...
1
vote
2answers
67 views

Why is entangling injectable with class that uses it a bad practice?

I have had this argument for a while, because I have noticed some people prefer "readable" code over properly structured one. So in the example I am showing, basically I have this Mapper class in ...
0
votes
3answers
271 views

Java constructors confusion? [closed]

public class example { private String one; private String two; public example(String one, String two) { this.one = one; this.two = two; } public static void ...
0
votes
1answer
91 views

Is it good practice to assign an instantiated class to a static property in the same class?

I have code that was written by someone else that goes like this: On a ViewModel: public static ACertainViewModel Default { get; private set; } On the same ViewModel's constructor: public ...
0
votes
2answers
141 views

Moving Java static variables into XML

I've been working on a small Java project by myself for a department that does not do a lot of software development but mostly database stuff. I showed my boss the code I've been writing and he saw ...
0
votes
2answers
130 views

Can there be value types in dynamic languages? [closed]

A value type is one whose instances are themselves saved in variables. A reference type is a type whose instances are saved somewhere and variables only hold the addresses of the instances. Some ...
0
votes
1answer
224 views

Design Pattern : Static Array/List in Class Object

I'm a CS alumni, but we didn't learn much by the way of OOP, or Design Patterns. I've heard the phrase C with iostreams and thought it fitting. Anyway that's besides the point. I am just curious about ...
0
votes
1answer
183 views

If everything is supposed to be an object in Java (barring primative types), isn't this contradicting the point of static? [duplicate]

I often write code which makes an object and then use static methods in static classes to manipulate said object. Am I missing the point of OOP? How do I know whether I'm thinking in the OOP mind ...
0
votes
0answers
28 views

Does VB.NET support the semantics of a local static array in an iterator function?

I'd like to do something like: case 1a: Private Iterator Function Names() As IEnumerable(Of String) Static ReadOnly mNames as String() = { "1", "2", "3" } For i As Integer = 0 TO ...
0
votes
1answer
104 views

When to used static visibility? [duplicate]

I can't attain the primary used of Static Visibility. My question is why they used static method & properties in this code? class PassHash { // blowfish private static $algo = '$2a'; ...
-1
votes
4answers
500 views

Why can you have statefulness inside a static class in java?

I was playing around with Java today and I read about static inner classes. Why can you have 'statefulness' inside of a static inner class. For instance: class outerClass { static class ...