static-methods

Help with C++ static method

Hello. Is it possible to return an object from a static method in C++ like there is in Java? I am doing this: class MyMath { public: static MyObject calcSomething(void); private: }; And I want to do this: int main() { MyObject o = MyMath.calcSomething(); // error happens here } There are only static methods in t...

C++ linker problems with static method

I'm writing a Vector3D class that calls a static method on a VectorMath class to perform a calculation. When I compile, I get this: bash-3.1$ g++ VectorMath.cpp Vector3D.cpp /tmp/cc5cAPia.o: In function `main': Vector3D.cpp:(.text+0x4f7): undefined reference to 'VectorMath::norm(Vector3D*)' collect2: ld returned 1 exit status The cod...

Are static methods good for scalability ?

Does static methods and class are good for scalability ? I think so static class/method improves scalability of application and instance methods doesn't scales much. So is it good programming practice to write static method where ever it is possible ? ...

How to develop methods which has the same functionality for some entities?

I have a framework of classes. Each class represents some entity and has basic static methods: Add, Get, Update and Delete. This methods made static because i want to allow perform some action without instantiating of the object. E.g., to add some object i have to do this: Foo.Add(foo). Now i want to have number of methods which woul...

What is the best approach to make data access methods in NHibernate?

For example, I have two classes: Foo and Bar. This classes are mapped to some tables. As for now, I have static methods for each class: Add, Update, Delete, Get. E.g.: public class Foo { private Guid _id; private string _someProperty; static Foo Get(Guid id); static void Add(Foo foo); static void Update(Foo foo); s...

Reference for the C methods used in iPhone development

Is there a good reference somewhere with all the C functions that can be used by default in iPhone development (I guess they lie in the Foundation framework)? I mean functions like: arc4random(), cos(), sinf(), hypot(), sqrt(), sqrtf() etc... They are so many considering their variations too (sin(), sinf()) and googling every single tim...

What could go wrong with calling a static method with an object in Java?

If I have the following: class A { public A() { } public static void foo() { System.out.println("foo() called"); } } public class Main { public static void main(String [] args) { A a = new A(); a.foo(); // <-- static call using an instance. A.foo(); // <-- static call using class } } Are there any problems that ma...

What are the gains of converting normal method to static?

As it is clear from question, if I convert a normal method to static what gains will I made? ...

Class design: allow a class to be used both as an object and also supply public static methods

I have a silly, little class "FileSystemSize" which can be used both as an object and also via public, static methods. The output is similar, but not identical in each case. The class was intially static, but I added the possibility to initialize it as an object to allow extending with new "convenience methods" in future versions, witho...

Namespace + functions versus static methods on a class

Let's say I have, or am going to write, a set of related functions. Let's say they're math-related. Organizationally, should I: Write these functions and put them in my MyMath namespace and refer to them via MyMath::XYZ() Create a class called MyMath and make these methods static and refer to the similarly MyMath::XYZ() Why would I c...

Why does my ASP.Net static function's "context" crossover between user sessions?

I think I need some help understanding how static objects persist in an ASP.Net application. I have this scenario: someFile.cs in a class library: public delegate void CustomFunction(); public static class A { public static CustomFunction Func = null; } someOtherFile.cs in a class library: public class Q { public Q() { ...

distinguishing between static and non-static methods in c++ at compile time?

For some tracing automation for identifying instances i want to call either: a non-static method of the containing object returning its identifier something else which always returns the same id My current solution is to have a base class with a method which() and a global function which() which should be used if not in the context o...

PHP custom static method access

Hi, I'm in PHP and I must access a Static method of an object which name must change. private $controlleur = null; private static $instance = null; private function __construct() { $nomControlleur = "Controlleurs\_" . Session::singleton()->controlleur; $this->controlleur = $nomControlleur::singleton(); } This p...

What are the advantages of immutable objects over static methods?

interface IDependency { string Baz { get; set; } } class Foo { IDependency dependency; public Foo(IDependency dependency) { this.dependency = dependency; } public void FubarBaz() { dependency.Baz = "fubar"; } } I could also implement this as: class FooStatic { public static void F...

How do parameters and their usage in methods effect the static/instance design decision?

Just a simple question: I have read that a class should be made static when it does not modify its instance. So if I have a class which is called Account and it has properties such as Id, Duration, etc and these do not get modified by the class, then this can be made static otherwise it should remain static. How does this (whether the ...

How to find static method calls in large Java project?

I'm refactoring some Java code to be more decoupled by changing some static method calls to non-static calls, for example: // Before: DAO.doSomething(dataSource, arg1, ..., argN) // After: dao.doSomething(arg1, ..., argN) My problem is that in a large project, it can be hard to find where static method calls are being made. Is there ...

in PHP, when should I use static methods vs abstract classes?

I'm under the interpretation that if I need to access a method statically, I should make the class abstract only if I'll never need it instantiated. Is that true? ...

static methods and the call stack in IIS/asp.net

Theoretical question. If you have 100 separate requests coming to an aspx web page that calls the static method below. public static GeocodeResult GeocodeQuery(string query) { int train, tube, dlr = 0; // manipulate these ints if (train) { // do something important } } ...

static method with polymorphism in c++

hi, I have a weird issue using polymorphism. I have a base class that implements a static method. This method must be static for various reasons. The base class also has a pure virtual method run() that gets implemented by all the extended classes. I need to be able to call run() from the static class. The problem, of course, is that th...

When is it best to use Static Functions in ASP.NET

Hi all, I have been wondering, When to use static functions and when not to in ASP.NET What are the advantages and disadvantages in using them, in various aspects like performance, following good practices etc (and many more, which ever you feel is relevant). Looking forward for your replies. Thanks, Mahesh Velaga. ...