Questions tagged [static]
The static tag has no usage guidance.
61
questions
1
vote
5
answers
308
views
How do Singletons differ from Static variables?
Although I do find some (apparently old) posts on the topic on the web, I could not find one here at SE. Thought of raising this here to see if what I read is accurate/is all there is to it.
So ...
3
votes
2
answers
127
views
File scope static variables with non-trivial destructors
I am coming from the Google C++ guidelines, specifically the section on Static and Global variables. It advises against having global variables of types that aren't trivially destructible. I'm unsure ...
1
vote
4
answers
375
views
How to convince colleagues to stop writing static classes [closed]
I recently joined a new company. After working on some projects I noticed a pattern. Every project contains a lot of static classes. A lot of static Helper classes. ApiHelper JsonHelper UmbracoHelper ...
3
votes
3
answers
347
views
Is there any performance hit associated by the definition of a static constructor or due to availability of it?
This question is mostly related to the way language implementer do implements static class initalization (pretty specialized question). It is for curiosity and also to potentially improve my code to ...
2
votes
2
answers
452
views
C99: Alternative to "static" variable declaration?
By coincidence I stumbled over "The New C Standard" from Derek M. Jones, where he comments this sentence from the C99 standard regarding "storage duration of objects":
There are ...
1
vote
1
answer
82
views
Identifying Risks/Gotchas When Using Static
I am intending to come from the perspective of development choices, code reviews, and general testing against defined environments (Development, Test, Production, etc.). I will be using C# as the ...
2
votes
1
answer
641
views
Storing static data idea — is it best practice?
I have a database in which I am storing a bunch of companies that can have several different types of codes associated with them — here is a example of a group of codes
I was wondering if storing them ...
-2
votes
1
answer
117
views
What is the best way to store secure static data which can be easily updated by clients?
I'm currently building an education website which contains a lot of content such as questions, videos and notes which all need to be securely locked away and exposed to users with relevant permissions....
3
votes
2
answers
974
views
what to use instead of finalize() in java
Let's consider following code:
class Table {
private static int number_of_Tables=0;
public Table(){
++number_of_Tables;
}
public void finalize(){
--number_of_Tables;
}
public static int ...
-2
votes
2
answers
188
views
C# Static & Constructor Logic [closed]
I learn C# and try to understand the logic between static and Constructor right now. One thing I need ask you about an example which I will give at below. (please ignore the quality of code or how ...
3
votes
1
answer
1k
views
Alternative to a utility class for extension methods in C#?
I understand that in OOP languages like C#, it is generally viewed as bad practice to create utility classes, and it's preferable to put methods in the classes in which they will be used.
To that ...
-1
votes
2
answers
173
views
Object composition in a static function
I have a class that provides basic functionality of a modal window. For different situations I need to provide different modals(different number of buttons, titles, etc...). I have a kind of factory ...
0
votes
1
answer
190
views
Is it a good idea to make huge objects dynamic in C++? [closed]
I have an engine and if I want to use the 3d system I always have to pass a pointer to any mesh renderer. If I would make the 3d system static then I just could use them. But the 3d system is big with ...
22
votes
5
answers
12k
views
Is the use of ***Helper or *** Util classes containing just static methods an AntiPattern
I am often confrontated with helper or util classes in Java or whatever kind of language.
So I was asking myself if this is some kind of Anti Pattern and the existence of these kind of classes is ...
2
votes
4
answers
873
views
Use of static methods to implement logic within a class
I've recently caught an odd behaviour in my own coding: At some point in the last year I began creating protected static methods to implement the logic of my public methods, ensuring that the ...
-1
votes
1
answer
116
views
How to Model below Hiearchy with OOP
Note that I cannot use static inheritance due to language limitations (Java).
There is a general Building class. Each instance of Building has properties that exist regardless of instance variables (...
-1
votes
2
answers
3k
views
C#, Static classes and Inheritance
As a beginner I'll try to explain my problem as good as I can:
I'm currently trying to program a "simple" ECS. My basic idea is that I have a base "Entity class" which includes all sorts of functions ...
12
votes
3
answers
10k
views
Java: Is it okay to abuse Spring beans (@Component) rather than use static final utility classes?
I'm torn between using DI and static utility classes on my code.
I currently created a DateUtil static class that is only meant to be accessed statically. This class is responsible for just creating ...
14
votes
4
answers
26k
views
Writing 'interfaces' for static classes
I'm writing a postcode validation library, so that I can call a helper method
var result = Postcode.IsValid(postcode, country)
To that end I need to have 'classes' that represent supported countries ...
2
votes
1
answer
470
views
Is usage of Nested classes an example of tight coupling ? (JavaFX)
So I'm working on this game where I have a nested class which has to get access to the member functions and variables of the outer class in order to perform it's functionalities. In particular the ...
0
votes
1
answer
1k
views
Access static constant via interface or abstract class in java without instantiating
Need an advice on how to achieve decoupling of UI graphs from content.
Preamble:
I have an abstract Sensor interface and a bunch of implementations. Interface defines a couple of functions, such as ...
2
votes
2
answers
355
views
What is the proper (or preferred way) to configure a static factory class?
First SE stack,
I am working on a large chunk of old Java code and am finding tons of duplication and inconsistently configured/created objects because of different authors, skill levels, etc.
I ...
0
votes
2
answers
4k
views
Static vs non-static in embedded systems [duplicate]
I am writing a C++ applications in the embedded area. A lot of times I think about should I use static or non-static const variable in the functions/methods? Here are my thoughts:
Static constant ...
1
vote
3
answers
3k
views
ASP.net MVC static class and background worker
I have an MVC 5 ASP.net app that is working perfectly. A colleague of mine has made a project that reads in data from files and churns some of it to output some calculations for me to display in the ...
1
vote
2
answers
216
views
What is a best design to hold a “global” mutable list?
Let's say that I have an ArrayList of class Person and I have two objects that are generated from two different classes which read and write to this ArrayList.
For example,
public class Main {
...
0
votes
2
answers
661
views
Does anonymous object instantiation have advantages over static object creation in this specific case?
In a Java program which I did not made and cannot change, only write extensions for it, the design forces me to create an object which will never be garbage collected. I tested and I can do it through ...
2
votes
3
answers
5k
views
Static Method in Interface
I'm working on software to play back log files. We have different types of logs from different providers.
I've created an interface that different classes will implement to play different logs. For ...
4
votes
2
answers
377
views
When to use a static method instead of a constructor?
I have a short question for you: let's imagine that we have a class similar to this one.
public class StreamTradeDataProvider : ITradeDataProvider
{
public StreamTradeDataProvider(Stream stream)
...
3
votes
3
answers
902
views
Should only static functions print to screen?
My question is more about trying to figure out if my belief is correct or valid in that a static method should be the only one that prints to the screen (let's say in a terminal). I am using Java and ...
5
votes
3
answers
374
views
Etymology of "static" functions
I get why static local variables are called "static" -- we want them to be allocated in static memory! But what is the reason for calling functions and variables we want restricted to the current file ...
-2
votes
1
answer
334
views
How does accessing class level variables in java work?
I'm doing my third online course in learning java because I couldn't get over how to even start a project from scratch. There was a lesson in this new course that made me ask this question of the code ...
2
votes
1
answer
6k
views
Collect and prcess data from multiple threads in Java
There is a Java program that reads a list of orders and for each order starts a thread that receives data from SQL and prints the list of items in a given order to an order_name.html. I want to write ...
7
votes
4
answers
3k
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 should be avoided.
Are static global variables equally bad?
In all my projects, I have heavily relied on static global variables. From design ...
0
votes
3
answers
440
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 ...
1
vote
1
answer
887
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 ...
16
votes
1
answer
8k
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&...
1
vote
2
answers
6k
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
2
answers
261
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 ...
12
votes
2
answers
5k
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 ...
12
votes
1
answer
8k
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 ...
0
votes
1
answer
250
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
1
answer
427
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 ...
1
vote
3
answers
773
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;
...
5
votes
3
answers
2k
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 ...
5
votes
3
answers
53k
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 ...
6
votes
2
answers
442
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 ...
1
vote
1
answer
1k
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
1
answer
245
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 ...
3
votes
1
answer
199
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 ...
3
votes
1
answer
5k
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 ...