Questions tagged [static]

The static keyword, in object-oriented programming languages, is used to define a function/method or field/property as bound to the context of a type/class, but not to any specific instance. Unlike constants, static properties can usually be changed at runtime. static also refers to the storage class in languages like C. static variables are initialized once, at run-time, and persist in between function calls (i.e. they aren't re-initialized).

Filter by
Sorted by
Tagged with
1
vote
1answer
59 views

Improving poor man's translations mechanism in c++98 program (follow-up)

As a follow-up to this question that was an attempt to add basic translation capabilities in an old c++98 program for the sake of the community, I'm posting here the first iteration of my code after ...
0
votes
1answer
106 views

Improving poor man's translations mechanism in c++98 program

In order to add basic translation capabilities in an old c++98 program I've come up to a basic and shameless code summarized by this snippet: ...
2
votes
2answers
96 views

PhoneBook in Java - follow-up

This is a follow-up to this phonebook code. This Phone Book allows the user to Enter a value between 1-3. Entering 1 lets the user Add a number to the phone book, when the process is finished, the ...
4
votes
1answer
245 views

Alternative std::function implementation for lambdas

I was trying to implement a faster, alternative implementation of std::function. I came up with the code below: ...
1
vote
0answers
15 views

Using (templated) function-scope static address as Unique ID [closed]

typedef const bool* const TypeID; template<typename> TypeID TypeIdOf() noexcept { static const bool idLoc(0); return &idLoc; } I'm using ...
4
votes
2answers
346 views

API for SQL queries with PHP PDO

I'm writing a very simple CRUD application, and I'm wondering if the way I'm using static methods throughout the code makes sense. I'd very much like to simplify ...
1
vote
2answers
280 views

Magic Static in Singleton Template

I recently was reading an article labeled "Modern C++ Singleton Template". The proposed solution used C++11 feature of Magic Statics (N2660). I wanted to adapt it for an own project in "...
1
vote
1answer
80 views

Json config loader class

Currently the class takes a json file and retrieves data from it, and i'd like to improve this class. ConfigLoader.h ...
4
votes
1answer
290 views

Bank with factory method for accounts, multithreaded deposit and withdraw

I have a couple questions about this program Should I implement runnable instead of using thread class? I like the idea of the consumer and producer being thread objects, it seems simpler to me, but ...
1
vote
2answers
76 views

Overriding static method with different static variable in java [closed]

Suppose I have 3 classes, Animal, Dog, and Cat ...
3
votes
1answer
38 views

PHP get minDateTime from array

I've written a function to get the smallest date from an date[ ] and check for null. If null == infinity ...
3
votes
1answer
91 views

Static Arrays and Variables (JavaScript)

I would like to know if this code of the database for my Pokemon clone game follows general practices in syntax and general readability. I feel like I could cut down on my comment usage, and place ...
4
votes
3answers
92 views

Function decorator for static local variables

I'm primarily a C++ developer, but I find myself writing significant amounts of Python these days. One C++ feature I miss in Python are function-scope static variables (variables which are initialised ...
2
votes
1answer
52 views

PHP - using static variables to store "client" for later use

I had this S3Helper class before such that, every time I called a function to any of its methods (which I haven't shown here, but which do things like upload files to s3 or get temporary s3 links), it ...
3
votes
1answer
81 views

Caching lookup values in an e-commerce website

I am working on an e-commerce website. I have a CarMake dropdown which contains car make names and their corresponding Id, for example: { 1:Alfa romeo}, { 2:Audi }, ...
0
votes
1answer
4k views

Python decorator to support static properties

Classes in Python do not have native support for static properties. A meta-class can rather easily add this support as shown below. Are there any problems programmers might experience if they use this ...
8
votes
3answers
2k views

Static utility class for string manipulation in C++

My programming foundations were formed in Java, but I've decided to only use C++ from now on for my projects as a personal learning experience. Static utility classes are common in Java; but I don't ...
4
votes
2answers
346 views

Translating Objective-C use of static and +(void)initialize to Swift

I am converting an old Objective-C class into Swift. My actual question is at the very end after all of the code. Here is a cut-down version of the Objective-C class: DateInfo.h: ...
0
votes
1answer
82 views

Generically call static methods

I currently have two (core) classes : ...
0
votes
1answer
326 views

Usage of static block vs. direct static variable initialization [closed]

Suppose, I have a data access layer class, where I want to specify database connection parameters. Usually, I do it as static variables and initialize it right after definition, e.g. see ...
0
votes
1answer
53 views

Logging util with static lambda function

So again, I am a bit confused about some notes that i'am getting from my reviewer. I have some kind of utils, to print/prepare log messages. Yea, maybe I am a bit fanatic java 8 lambda guy but I think ...
1
vote
1answer
3k views

Static wrapper class for log4net Logging - thread safety

I'm using log4net in my application and have a static Log class which creates an instance of ...
6
votes
1answer
793 views

Fake duck typing with dynamic

There are sometimes situations where you have a couple of related classes with static fields or properties but you cannot access them via ...
2
votes
0answers
38 views

Multiple CResourceUsers using a single CResource

I need multiple CResourceUsers to share one instance of CResource. I want to instantiate the ...
0
votes
2answers
168 views

Read employee number and salary (exercise to use static keyword)

WAP to create a class called Employee having empid and salary as data members and salary as data members. Create objects of this class and count no. of employees working in an organization using ...
3
votes
2answers
747 views

Web browser in Swing with MVC

Follow up question to: Utilizing OOP when creating a web browser After I received help on the question above, I've created 3 classes for my Browser. ...
1
vote
2answers
79 views

Manipulating an ES6 static class property that is an array

I've been trying to find a way to create static properties in ES6 classes and have found a solution with the help of various Stack Overflow answers (namely this one and this one). However, I also ...
2
votes
2answers
2k views

Creating lists of Card objects

I need to create two lists of Card objects in C#. A Card class is defined as: ...
2
votes
2answers
7k views

Using Autofac to do DI in a static factory method

I'm using Autofac to create one of my classes inside of a static factory method Create. This code is working and I haven't noticed any side effects yet. Admittedly, ...
1
vote
2answers
212 views

Creating Immutable Student Object

For a project I'm working on I have the following requirements: We have two student types: Domestic and International ...
3
votes
1answer
1k views

Static helper function to set a property on another object

A situation has come up in which we have a block of code that will be repeated in multiple files, and this block of code has to: Create some object based on the values of other controls/properties. ...
12
votes
3answers
6k views

Implementation of static_for to iterate over elements of std::tuple using C++17 features

I have implemented a static_for loop to iterate over the elements of an std::tuple using C++17 features. Here is what I have ...
3
votes
1answer
495 views

Instance registry for keeping track of class instances

In my project, I need to be able to iterate through all living instances of a given class. I ran into a problem regarding static initialization/deinitization order where when an instance attempts to ...
0
votes
1answer
804 views

C# API Wrapper with Static Function Calls

I'm creating a wrapper library for an API, and I hit a block on how to redesign it. The entire library is static, and I'd like to change it to make it more testable. The library's goal is to make ...
2
votes
0answers
378 views

Threadsafe static initialization of ExecutorService

I am trying to create a threadsafe singleton class based on Initialization-on-demand holder idiom . Here is my code ...
2
votes
2answers
4k views

SQL connection in static class and wrapper

I need to make some calls to stored procedures in my SQL database from a .NET application, using C#. I have something like this, and I put just one of the methods but the rest will be similar: ...
1
vote
0answers
380 views

Utility classes for XML

I have a class which makes calls to a static class. this class started off as a test utility class, primarily for performing operations on xml via XPath. Eventually some of the methods in the XmlUtil ...
1
vote
1answer
76 views

Improving Design for structured Keys

On several occasions I had to use a fixed set of keys (constants in the sense of static final String) with some additional logic (grouping in different keySets). After some more or less lefthanded ...
1
vote
1answer
2k views

Enum of calculator operations

I'm making my first simple project which I decided would be a calculator and I'm kind of stuck on implementing the operations. I have two classes one of which is the GUI part and the other one ...
6
votes
2answers
1k views

Fill a vector with uniformly distributed random complex numbers

I want to fill an array of complex numbers using a uniform generator. I thought up the next code. (Complex is a simple fixed-point complex data type.) ...
1
vote
0answers
716 views

Mocking protocol with class/static functions in Swift

I am using one of the open-source Objective-C keychain wrappers to store data in iOS keychain. For test cases, I have created protocol as: ...
-1
votes
2answers
284 views

Initializing a big static array for a card-based iOS app

I have a card-based iOS app that uses a sizable static array of cards. Each card has several properties, mostly strings, numbers and boolean. The first version of this app had 3-4 properties. The ...
2
votes
1answer
254 views

A simple Dice Game Using only Static methods

This is a simple dice game that requires you to get two numbers from the user and then it generates 15 other numbers and checks if the generated numbers are the same as the numbers typed in. Try to ...
2
votes
1answer
84 views

Server side of a chat program - part 2

A few days ago I posted a question about my code. It was obviously awful and thanks to some advice from Hosch250 I learnt a lot of things about OOP. Now, I rewrote the program. To me it seems a ...
4
votes
1answer
413 views

Getting enum values of Pseudo-Enum classes

By "Pseudo-Enum" classes I mean cases where someone's used a class with public static properties to emulate enum behaviour; e.g. as described here. Per the example below, this is useful for classes ...
1
vote
0answers
142 views

Android Internal Resource Reader

I'm not really sure if this is right, so it would be great to have it reviewed. I'm creating an Android library and made a final class with completely static methods for getting internal resources (...
4
votes
4answers
253 views

Client to connect to server and show a text menu

First of all: Sorry for my English, that said... I am developing an obligatory for my University, so far it has a class that provides the user with options to connect to a server (once connected it ...
-2
votes
1answer
95 views

Updating contacts in mobile phone simulation

I'm currently making a mobile phone simulation, using a custom object in an ArrayList. I was wondering if there was any difference in using these two following ...
3
votes
4answers
604 views

CSV parsers and OrderedDictionary

I wrote the following (static) class to read files easily in C#. However, it is a static class, so I wonder if there would be a gain to make it a non static method (and therefore, passing arguments as ...
1
vote
1answer
943 views

Unit test Web API controller that uses a static helper class which uses app config setting

I have a situation where I have a static class that reads my application configuration file for some configuration value. When unit testing Web API controllers that make use of this static class I am ...