Skip to main content

Questions tagged [static-access]

in object-oriented programming, access from a static (class) context, as opposed to one from a particular object instance context

1 vote
2 answers
2k views

Best way to access (grand grand) parent element in gui

I'm creating a multi window gui program, in c++ with Qt Widgets. I do have many custom gui elements, which usually are c++ classes inherited from QWidget or other Qt elements. When foo is the main ...
Turtle10000's user avatar
3 votes
2 answers
431 views

What is the rationale for making certain methods for data types static?

In C#, for instance, there are static methods for telling if a string is null or empty, finding an element in an array, clearing an array, etc. However there's an instance method for replacing ...
Ace's user avatar
  • 637
0 votes
3 answers
2k views

Usage of objects as services in static functions

The goal within my framework is to provide facades or front-facing functions/APIs so that people can easily interact with my system, as such, in most cases, that goes super well by having static ...
Daniel M's user avatar
2 votes
3 answers
404 views

How to model a Struct with a limited set of values that behaves like an enum?

I have a general organization problem with my code. I'm modeling DNA, and I've created a Nucleobase struct to store the "letter" of the DNA. For ease of use, I would prefer the following functionality ...
Adam B's user avatar
  • 1,660
0 votes
1 answer
137 views

Is singleton use acceptable for static single responsibility?

I have been reading into possible design patterns and have found the use of singletons always referred to as an anti-pattern. I am currently using a singleton for the sole purpose of gathering ...
Necro's user avatar
  • 105
2 votes
1 answer
9k views

Why isn't there a static initializer in Python?

The equivalent of static { // Code here } does not exist in Python by default. The closest thing, while being "Pythonic", seems to be to create a decorator and do the initialization there such as:...
Utku's user avatar
  • 1,912
1 vote
1 answer
3k views

Should I avoid long method chaining simply to get a variable? [duplicate]

I am working on a game, and I have many instances where I have to do something like this: Game.getInstance().getEnergyDropManager().getDrops() Or: this.dimensionSelector.selectDimension(Game....
MCMastery's user avatar
  • 173
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 ...
YianniW's user avatar
  • 191
37 votes
3 answers
7k views

Why is there no static keyword in Kotlin?

Kotlin is known primarily as a drop-in replacement for Java, but it gets rid of a well-known Java construct: the static keyword. Instead, that class-level functionality is offered mainly by companion ...
user1446's user avatar
  • 492
0 votes
1 answer
139 views

Static field injection into subclasses

Say that I have a C++ class with some fields with static storage duration, call it class A. Is there some way to use inheritance to "inject" these static fields into classes which derive from class A?...
MattyZ's user avatar
  • 113
5 votes
1 answer
2k views

Why shouldn't a static class have an internal state?

While working on a project, I decided to create a database class to manage my DB connection. I started looking for the best practice to do that, which is usually either a static class or a singleton ...
Wisam Shaker's user avatar
6 votes
2 answers
238 views

Deterministic statics vs inject-able classes

I have in mind several deterministic functions that I'd like to put together, but I'm struggling with the full impllications of doing: Static class with static methods Instance of a class that can be ...
Kritner's user avatar
  • 394
1 vote
1 answer
5k views

Abstract classes with static methods in PHP

Pre: I am looking at a quite big PHP project developed by a company which we need to partly interact with while building a new webapp. The whole application is developed in PHP 5. Most of the ...
GavinoGrifoni's user avatar
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 '...
Vincent's user avatar
  • 383
0 votes
0 answers
168 views

Will this singleton style class work with accessing a session on multiple MVC controllers?

Question background: I have an e-commerce site I'm developing that requires multiple controller methods to access a single session variable. The idea: My idea was to create a singleton style class ...
user1352057's user avatar

15 30 50 per page