Questions tagged [static]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
-2
votes
2answers
102 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
1answer
239 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 ...
0
votes
2answers
93 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
1answer
184 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 ...
19
votes
5answers
4k 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
4answers
493 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
1answer
113 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 (...
0
votes
2answers
1k 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 ...
7
votes
2answers
3k 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 ...
6
votes
3answers
7k 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
1answer
263 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
1answer
559 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 ...
1
vote
2answers
194 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
2answers
2k 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
3answers
2k 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
2answers
178 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
2answers
462 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
3answers
4k 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
2answers
252 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) ...
2
votes
3answers
595 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
3answers
313 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
1answer
217 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
1answer
3k 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 ...
4
votes
4answers
1k 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
3answers
410 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
1answer
590 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 ...
12
votes
1answer
5k 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&...
0
votes
2answers
4k 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
218 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 ...
7
votes
2answers
3k 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 ...
10
votes
1answer
5k 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
1answer
187 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
1answer
408 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
3answers
388 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
3answers
1k 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 ...
4
votes
3answers
42k 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
2answers
397 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
1answer
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
1answer
226 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
1answer
189 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
1answer
3k 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
80 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 ...
7
votes
3answers
12k 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 ...
5
votes
4answers
14k 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 ...
0
votes
4answers
2k 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 ...
0
votes
1answer
558 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 ...
5
votes
3answers
7k 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 ...
0
votes
1answer
141 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'; ...
9
votes
6answers
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 ...
5
votes
2answers
2k 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 ...