static-methods

Is there an alternative to the Curiously Recurring Template Pattern?

I've caused myself some headaches over the past couple of weeks with the curiously recurring template pattern. Following on from these two questions of mine: What’s the correct way of retrieving my custom enumeration classes by their value? Why are my static objects not being instantiated when first access to the static class is a sta...

Does a static method share its local variables & what happens during concurrent usage from different threads?

C# Question - I'm trying to determine whether it is OK to use a static method where, within the method it does have some local variables it uses. Are the local variables "shared" across usages of the method? What happens for example if the static method is being called/used at the same time from different threads? Does one thread bloc...

how to create an object from given class name in php?

I have a variable $className which is name of declared class in php and I want create an object of this class lunch a static method of this class ...

How garbage collection works on object references?

I am confused about garbage collection process on objects. object A = new object(); object B = A; B.Dispose(); By calling a Dispose on variable B only, the created object will not be garbage collected as the object is still has referenced by A. Now does the following code work same as above? public static image Test1() { ...

Can you hydrate a static property using MEF?

can I hydrate this inside the class's static constructor? public class Connect:IDTExtensibility2, IDTCommandTarget static Connect() { //hydrate static properties? } [Import] public static Action<ProjectLogicChecks> Display { get; set; } [Export(typeof(Action<ProjectLogicChecks>))] private static void Displ...

Is it ok to hide a static method?

I have an abstract Catalog class as follows. It has a static method OpenCatalog() which is used to return a specific concrete catalog based on the type of location provided. Once it has determined the type of catalog it then calls a specific OpenCatalog() method of the correct concrete catalog type. For example I may have an implementati...

Creating a container 'thing' in C++ to hold static functions. What should 'thing' be?

Hi there. I'm currently building a set of common functions (Search algorithm implementations), and think I'm doing the grouping wrong. At the moment, I have a class, Sorting, that is declared in a file called Sorting.h (it's nowhere near finished yet, btw) like so: #ifndef SORTING_H #define SORTING_H #include <vector> class Sorting { ...

Static repository... can't use DI, what to do?

I am in a situation where we need to modify what is being returned from the static repository in a 3rd party open-source application (NopCommerce). The problem is that they use static repositories, so I can't merely inherit an interface and DI my own repository. I'm trying to do this without modifying the NopCommerce code-base... any f...

Simple static methods (Console) help

Hi guys, this is my first time posting my problem here, i hope i get help :) My Problem: I am trying to display the "This Old Man" (first two stanzas only) in the Console. I am beginning to learn methods, so please bear my n00bishness. The Song goes: This old man, he played one He played knick−knack on my thumb With a knick−knack pad...

Extension-methods VS static method resolution - what do I miss in spec?

Hi! I've added an extension method that is a shortcut to string.Format: public static string Format(this string format, params object[] args) { return String.Format(format, args); } When I invoke this method like this: "{0}".Format(1); everything works like a charm. While "{0}".Format("1"); does not compile with this error...

How can I add a static method to a QInputDialog for returning custom data?

QString QInputDialog::getText ( QWidget * parent, const QString & title, const QString & label, QLineEdit::EchoMode mode = QLineEdit::Normal, const QString & text = QString(), bool * ok = 0, Qt::WindowFlags flags = 0 ) [static] This function is defined to call a dialog get and return the text which will be inserted in ...

Generics in static factory methods? (Java)

I have an assignment that is requiring me to use the factory pattern for implementing an immutable data structure, but the problem is that the abstract class is generic, and having static methods make references to generic types is giving me problems. My assignment is requiring me to use static methods so I'm starting to panic. Any hel...

Accessing SharedPreferences through static methods

Hello, I have some information stored as SharedPreferences. I need to access that information from outsite an Activity (in from a domain model class). So I created a static method in an Activity which I only use to get the shared preferences. This is giving me some problems, since apparently it is not possible to call the method "getSh...

How can I call an Objective-c static method asynchronously?

How can I call a static method asynchronously? + (void) readDataFromServerAndStoreToDatabase { //do stuff here //might take up to 10 seconds } ...

Is it normal practise to have getters which call private methods in API design?

Hi, Is it common, in API Design, to do something like this: public ReadOnlyCollection GetCollection { get { // Get's read only collection here... } } In the body of the get, this calls a private method that fills the collection. So I only expose one, consistent object to clients. The thing which confuses me is if it is right to make...

Regex.Replace and static context?

Hello, I have this code here: private Func<string, string> RemoveSpecialChars = str => Regex.Replace(str, "[ ./\\-]"); Its complaining (Can not access non-static method Replace in static context) about the call to Replace, because of static context. Whats wrong? Thanks :) ...

xCode / declaring Static Methods in class

Anyone know how I can declare a static method for an xcode class and then use it in my project? I want to create a Common.h class and then do something like this in one of .m file Common.MyStaticMethod(); I dont want to have to instantiate and instance of Common ...

A class that only has static data and methods to access these data. How to implement that properly?

I know that is a beginner's question. I'm new to java and and also to programming in general. Say I got a class that has only static data, example: class Foo { private static int x; } I want to use the class without instantiating any object. So I want to be able to do: Foo.setX(5); Foo.getX(); What is the best way to implement th...

static method as default parameter to a class method

My question is about two answers to another question: http://stackoverflow.com/questions/3083692/using-class-static-methods-as-default-parameter-values-within-methods-of-the-same. I am trying to understand if there's really a difference between what the two answers do, and if so, what's the pros and cons of each. Question: how to use ...

Static Method Confusion

I am working with Asp.NET and I have a class named PathFinder which has methods like StyleBarPath(string BrandId,string ProductId) which returns for example a combination of path including brandId and productId and also there are such methods in the same class. What I am thinking to make them static methods to invoke them easily in ever...