Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [static]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
92 views

IOC life cycle and static class

Does discussing the behavior of static classes make sense for IOC? It seems that in the case of a life cycle transient such a description is misleading and untrue: However, it is guaranteed to be ...
user1785960's user avatar
0 votes
5 answers
257 views

When, if ever, should a private member variable, used in one function, be made into a local static variable?

Lately, I have been playing with this idiom: Changing a private member variable into a local static variable when: member to singleton class used in only one function member is mutex for a shared ...
Anon's user avatar
  • 3,613
-3 votes
2 answers
306 views

Why would I use Gatsby instead of Manual HTML / CSS when creating a static site?

These days, I see people always extolling the benefits of using Static Site Generators (SSG) for building static sites. Why would I not just write the HTML/CSS myself? What's the advantage of using an ...
IntelliData's user avatar
1 vote
1 answer
664 views

Should I use private field or static variable in my method?

There is a variable that must persist between calls but otherwise only one method uses it. As it is a method of the object, the value can be persisted as a private field of the object, or otherwise it ...
h22's user avatar
  • 937
0 votes
6 answers
922 views

Is a static class full of static methods a code smell?

I have to create custom buttons but in order to encapsulate the logic of button creation I've this class (VB.net): Public Class ButtonCreator Public Shared Function CreateBaseButton(Optional ...
Mateo Ezequiel Bertogliati's user avatar
0 votes
1 answer
360 views

Observer pattern using static events

I'm working on a game prototype: I have a Cell class which, given a mouse click on its collider, can raise an event that should be listened in two different modules: Camera and UI. The Observer ...
vandermies's user avatar
0 votes
1 answer
262 views

Why exactly was the C++ convenience of not requiring a second declaration, removed?

See "Note" on second page: This convenience gave rise to serious inconsistencies and was removed several years ago The book was authored in 2003. What exactly does it mean by "...
Anon's user avatar
  • 3,613
0 votes
2 answers
686 views

Best practice for storing a static pdf file in a web app

I've to store a static pdf with an user guide of my application. I'm using Spring boot and Angular 12, what is the best way to store it? Put the file on resource folder of Spring boot? Put the file ...
Accollativo's user avatar
2 votes
2 answers
4k views

Dependency Injection vs Static Dependencies

I am building a wrapper for a library that requires little complex logic. The whole project is 8 builder classes, 4 classes for doing some pre-processing, and a couple visitor classes. Essentially I ...
EspressoCoder's user avatar
3 votes
5 answers
4k 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 ...
Veverke's user avatar
  • 451
3 votes
2 answers
1k 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 ...
Zoso's user avatar
  • 241
1 vote
4 answers
1k 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 ...
Roy Berris's user avatar
3 votes
3 answers
988 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 ...
Eric Ouellet's user avatar
2 votes
2 answers
1k 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 ...
mic's user avatar
  • 137
1 vote
1 answer
301 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 ...
eparham7861's user avatar
2 votes
1 answer
2k 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 ...
Jamie's user avatar
  • 139
-2 votes
1 answer
503 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....
Ryan_DS's user avatar
  • 107
4 votes
2 answers
2k 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 ...
user12394078's user avatar
-2 votes
2 answers
456 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 ...
Melih Cinar's user avatar
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 ...
Tara's user avatar
  • 151
-1 votes
2 answers
224 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 ...
7368616d696c's user avatar
0 votes
1 answer
192 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 ...
Kerbo Games's user avatar
24 votes
5 answers
15k 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 ...
Diversity's user avatar
  • 349
2 votes
4 answers
1k 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 ...
JohnLBevan's user avatar
-1 votes
1 answer
117 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 (...
Mario Ishac's user avatar
-1 votes
2 answers
4k 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 ...
Maxracer's user avatar
16 votes
3 answers
16k 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 ...
mpmp's user avatar
  • 821
17 votes
4 answers
38k 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 ...
Quango's user avatar
  • 291
2 votes
1 answer
541 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 ...
johndoe123's user avatar
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 ...
stiebrs's user avatar
  • 113
2 votes
2 answers
728 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 ...
finleyarcher's user avatar
0 votes
2 answers
5k 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 ...
VP.'s user avatar
  • 139
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 ...
Simon Nicholls's user avatar
1 vote
2 answers
248 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 { ...
CrazySynthax's user avatar
0 votes
2 answers
796 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 ...
user5950's user avatar
  • 113
2 votes
3 answers
6k 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 ...
001's user avatar
  • 273
4 votes
2 answers
907 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) ...
masm64's user avatar
  • 349
4 votes
3 answers
1k 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 ...
Alexis Evelyn's user avatar
5 votes
3 answers
430 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 ...
Elliot Gorokhovsky's user avatar
-2 votes
1 answer
469 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 ...
Rafael Cortes's user avatar
2 votes
1 answer
7k 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 ...
sixtytrees's user avatar
8 votes
4 answers
6k 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 ...
Sandeep's user avatar
  • 179
0 votes
3 answers
453 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 ...
gordon sung's user avatar
1 vote
1 answer
1k 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 ...
sd1517's user avatar
  • 151
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&...
user3748908's user avatar
  • 1,647
1 vote
2 answers
7k 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 ...
Wabbage's user avatar
  • 69
0 votes
2 answers
269 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 ...
Aviv Cohn's user avatar
  • 21.4k
12 votes
2 answers
6k 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 ...
ycomp's user avatar
  • 267
13 votes
1 answer
9k 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 ...
Deduplicator's user avatar
  • 9,051
0 votes
1 answer
282 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 ...
Tyress's user avatar
  • 153