The static-methods tag has no wiki summary.
-1
votes
4answers
264 views
Is static going to make any difference in this code snippet
I have been to an interview and was asked this question - is there any difference adding or removing the static keyword in these classes?
I know what static means but my understanding of this point ...
3
votes
1answer
132 views
How can I use the “Non-Member Functions Improve Encapsulation” pattern from C#?
In 2000, Scott Meyers argued that non-member functions improve encapsulation. In C++, a non-member function is a C-style global function:
...
2
votes
2answers
125 views
Can a class method be accessed both in an instance and statically?
I am relatively new to class design and I have a task that I'm not sure how best to complete, or whether my idea in general is a code smell.
I'm developing a RPG where people can own monsters, so ...
1
vote
2answers
236 views
Is using multiple static classes with maximum one public method is a good idea
I'm writing a structural detailing (CAD) software for concrete buildings in C#. I have defined like hundreds of static classes each with one public method and if needed some private methods. Each one ...
1
vote
2answers
333 views
Programming against interfaces in Java
Supposing I have an interface Foo and a given implementation FooImpl.
public class FooImpl implements Foo
If I want to define a new operation on this class that depends on the particular ...
0
votes
1answer
177 views
Static and not-static: programmer quantum theory
Let me illustrate using the PHP language. The discussion here is, how should I do exactly to solve this problem in a clear and unambiguous mode.
Imagine that I have a class called Path. This class is ...
0
votes
1answer
385 views
Why overriding a static method does not result in polymorphism in java
Many say that we can not override a static methods.
But we can override a static method.
The question is, when we override a static method why it does not result in polymorphism ?
0
votes
1answer
141 views
Static methods vs Interface implementation
Here is my problem:
I stared to create a e-commerce web sites info collector.
So i created a parser for each site.
The parser class is state less.
got methods like:
getItemPrice(WebElement page)
...
0
votes
3answers
211 views
Drawback of using static method [duplicate]
For methods that never access instance variable or static variable and they act just like a function (name-spaced) and they are deterministic base on only the input arguments , I want to ask, are ...
1
vote
2answers
265 views
Is this a candidate for Singleton?
I have an external thermometer connected via USB that is controlled by my SW. Different parts of my system will use it but never at the same time (all in one thread). However, it is a single device ...
18
votes
3answers
2k views
Why is a private member accessible in a static method?
The following is pseudo code, I tried it in Java and PHP and both worked:
class Test {
private int a = 5;
public static function do_test(){
var t = new Test();
t.a = 1;
...
0
votes
1answer
246 views
static or non-static, that is the question? [duplicate]
For comparisons / evaluations of objects of the same class(and other purposes), is it better to define a static or a non-static (is this called "dynamic" by chance?) function?
Sample code:
class ...
2
votes
1answer
2k views
Calling static method from instance of class
As a developer I am fan of static methods.
Recently I come across difference between OOP languages about this static methods.
All OOP language use static method to access any method without ...
13
votes
7answers
857 views
Is it a code smell if you are frequently creating an object just to call a method on it
I inherited a code base where there is a lot of code that goes something like this:
SomeDataAdapter sda = new SomeDataAdapter();
sda.UpdateData(DataTable updateData);
And then sda is never used ...
2
votes
4answers
2k views
Mocking static methods
Having recently returned from a Test Driven Development (TDD) course I had the following thought.
While writing unit tests using Mockito we came up against of the problem of mocking static methods. ...
1
vote
3answers
150 views
Refactoring - Utility classes behavior under a common interface
I was suggested to put my question here, so I'm doing so ;)
I need a common interface which represents some specific behavior:
public interface Contract(){
public void methodA();
public void ...
1
vote
3answers
349 views
Is it good to create static method at Visual Studio refactoring?
There are various refactoring options in Visual Studio to use at the time of coding. When we extract and create a new method. Then Visual Studio decide whether the new method will be static or ...
4
votes
5answers
505 views
Requring static class setter to be called before constructor, bad design?
I have a class, say Foo, and every instance of Foo will need and contain the same List object, myList.
Since every class instance will share the same List Object, I thought it would be good to make ...
4
votes
2answers
607 views
Should I put utility methods inside a class?
I have been working on a library which contains a large set of functions. For the sake of simplicity, I am going to use just one set as an example.
I am not sure which is the better way, in terms of ...
0
votes
2answers
326 views
Factory-Class versus Static Class
I've got a little problem in choosing the best design.
I have some (5 at the moment) image processing operations in my coe (Java). Every processing step independent from the other ones and consoists ...
0
votes
4answers
478 views
substitute for static inheritance
I currently have a number of classes (~20) that all do the same thing (abstractly), namely, generate an instance of a particular class from an xml file.
The way that they use the content of the xml ...
2
votes
2answers
316 views
Static or non-static?
For example I have these two classes:
First
public class Example
{
public Example()
{
}
public int ReturnSomething
{
return 1;
}
}
Second
public class Example
...
1
vote
1answer
1k views
JavaScript static methods retrieval
I have been thinking about it and wanted some feedback, recently I thought about doing it like this:
function foo(){
if ( !foo.prototype.statics ){
foo.prototype.statics = {
// ...
-1
votes
4answers
873 views
Immutable vs mutable object as returned parameter for class method [closed]
There is a class method (static method) in which I create and build some object. And for filling that object, I create it as mutable object.
My mutable object is a subclass of immutable object. So ...
3
votes
3answers
2k views
What is a static method compared to instance/class/private/public methods?
I'm learning programming in Objective-C and I can't understand what a static method is. I know what class/instance/private/public methods are. Can someone explain what it is using an example and ...
4
votes
1answer
421 views
How to implement syntax sugar in OO
The Problem
I regularly find myself writing the same code over and over again.
For example if I want a value from a nested array structure I end up writing something like this:
$config = ...
2
votes
3answers
2k views
OO PHP static keyword, should I use it?
I'm writing script for fb and I have 3 objects that I'll be using through all classes. I'm wondering if there is any advantage in using the static keyword except I don't have to create an instance ...
8
votes
3answers
224 views
“static” as a semantic clue about statelessness?
this might be a little philosophical but I hope someone can help me find a good way to think about this.
I've recently undertaken a refactoring of a medium sized project in Java to go back and add ...
2
votes
3answers
540 views
Syntactic sugar in PHP with static functions
The dilemma I'm facing is: should I use static classes for the components of an application just to get nicer looking API?
Example - the "normal" way:
// example component
class Cache{
abstract ...
-3
votes
2answers
1k views
Why don't inherited methods use child properties? (PHP)
I'm trying to get the code below to work in child classes. But it keeps failing because it is checking the basicDbClass rather than the child class.
For those complaining and voting my question down ...
4
votes
4answers
1k views
Could implicit static methods cause problems?
This is a purely hypothetical question.
Say I create a class method that contains no references to instance variables or other resources. For example (C#):
protected string FormatColumn(string ...
1
vote
3answers
288 views
Using static in PHP
I have a few functions in PHP that read data from functions in a class
readUsername(int userId){
$reader = getReader();
return $reader->getname(userId);
}
readUserAddress(){
$reader = ...
43
votes
6answers
7k views
How to deal with static utility classes when designing for testability
We are trying to design our system to be testable and in most parts developed using TDD. Currently we are trying to solve the following problem:
In various places it is necessary for us to use static ...
3
votes
3answers
8k views
Static class vs Singleton class in C# [duplicate]
Possible Duplicate:
What is the difference between all-static-methods and applying a singleton pattern?
I need to make a decision for a project I'm working of whether to use static or ...
13
votes
15answers
12k views
When do 'static functions' come into use?
OK, I've learned what a static function is, but I still don't see why they are more useful than private member functions. This might be kind of a newb-ish question here, but why not just replace all ...
3
votes
1answer
353 views
Is @staticmethod proliferation a code smell?
Consider a Python class with a number of @staticmethod methods and few instance methods. The static methods don't accept an instance of the defining class as parameters.
Do you think that all these ...
6
votes
3answers
5k views
Do private static methods in C# hurt anything?
I created a private validation method for a certain validation that happens multiple times in my class (I can't store the validated data for various reasons). Now, ReSharper suggests that the function ...
36
votes
9answers
13k views
Can't I just use all static methods?
What's the difference between the two UpdateSubject methods below? I felt using static methods is better if you just want to operate on the entities. In which situations should I go with non-static ...
15
votes
5answers
7k views
What is the difference between all-static-methods and applying a singleton pattern?
I am making a database to store information about the users of my website (I am using stuts2 and hence Java EE technology). For the database I'll be making a DBManager. Should I apply singleton ...
5
votes
3answers
1k views
Static methods or static functions?
I was just reading http://stackoverflow.com/questions/155609/what-is-the-difference-between-a-method-and-a-function and all of a sudden, the thing came to my mind was the static methods.
As static ...
44
votes
10answers
20k views
Is static universally “evil” for unit testing and if so why does resharper recommend it?
I have found that there are only 3 ways to unit test (mock/stub) dependencies that are static in C#.NET:
Moles
TypeMock
JustMock
Given that two of these are not free and one has not hit release ...