Questions tagged [private-methods]
285 questions
9
votes
6 answers
private method in inheritance in Java
I have confusion about using private methods in inheritance, for example:
public class A {
private void say(int number){
System.out.print("A:"+number);
}
}
public class B extends A{
public void say(int number){
…

pei wang
- 295
- 2
- 8
- 17
9
votes
2 answers
Python double underscore mangling
I am a bit confused by this behavior (using python 3.2):
class Bar:
pass
bar = Bar()
bar.__cache = None
print(vars(bar)) # {'__cache': None}
class Foo:
def __init__(self):
self.__cache = None
foo = Foo()
print(vars(foo)) …

gnr
- 2,324
- 1
- 22
- 24
9
votes
3 answers
Good naming convention for private member functions in C++?
For members, I use
//.......vv
SomeType m_XXX;
//.......^^
I'd love to use _ as a prefix for member functions, but names starting with _ or __ are reserved and should not be used.
My idea is, that when I have:
SomeClass…

Kiril Kirov
- 37,467
- 22
- 115
- 187
9
votes
2 answers
Ruby module_function, invoking module's private method, invoked in class method style on module shows error
test_module.rb
module MyModule
def module_func_a
puts "module_func_a invoked"
private_b
end
module_function :module_func_a
private
def private_b
puts "private_b invoked"
end
end
class MyClass
…

Jignesh Gohel
- 6,236
- 6
- 53
- 89
8
votes
3 answers
Objective-C: Should I declare private methods?
I've been declaring private methods in class extensions, according to Best way to define private methods for a class in Objective-C.
But, I just realized that, in Xcode 4, if I leave out the declaration of a private method altogether and just…

ma11hew28
- 121,420
- 116
- 450
- 651
8
votes
5 answers
How to define private methods in a JS Class
I'm trying to define a private method for a class to test that such a method can't be called from outside the class. However, I'm coming across an error even when I'm using the syntax as indicated in the Specification. I also checked MDN.
Here's the…

Mauric.io
- 111
- 1
- 2
- 6
8
votes
4 answers
How do I define private or internal methods in object oriented Perl?
I'm using Damian Conway's "inside-out" objects as described is his wonderful book Perl Best Practices to construct an object-oriented interface to a security system at my client. I'm coming across the need to use internal helper methods within my…

ennuikiller
- 46,381
- 14
- 112
- 137
7
votes
5 answers
C++ Private Functions: Whether to pass class member variable by function parameter, or not
Here's a question that comes up again and again in C++ class implementation. I'm curious about what people's thoughts are here. Which code do you prefer and why?
class A
{
public:
/* Constructors, Destructors, Public interface functions, etc.…

Chris A.
- 6,817
- 2
- 25
- 43
7
votes
4 answers
Private methods in a Category, using an anonymous category
I'm creating a category over NSDate. It has some utility methods, that shouldn't be part of the public interface.
How can I make them private?
I tend to use the "anonymous category" trick when creating private methods in a class:
@interface…

cfischer
- 24,452
- 37
- 131
- 214
7
votes
1 answer
Testing private methods that take generic type using PrivateMethodTester
How can I test a private method that takes a generic type using privateMethodTester in scala?
Let's say I have the following method:
private def parseValueForJsonKeyWithReturnType[A: TypeTag](
node: JsonNode,
key: String,
defaultValue:…

Nithin Chandy
- 686
- 1
- 10
- 28
7
votes
2 answers
Why can't I access private class methods in the class's companion object in Scala?
I'm working on a homework assignment for my object oriented design class, and I'm running into trouble with Scala's companion objects. I've read in a few places that companion objects are supposed to have access to their companion class's private…

Shaun
- 625
- 1
- 6
- 17
7
votes
1 answer
mocks - how to verify private method was called
I am trying to mock a private method and verify it has been executed.
The mocking itself works fine, that is I am getting correct results whether I comment/uncomment the 'when' line. However, I am having troubles with…

Łukasz
- 1,980
- 6
- 32
- 52
7
votes
2 answers
How to call a private method that exists inside a private inner class
I want to test a private method that existe inside a private inner class
public class MyBigClass {
private class MyInnerClass {
private void wantedMethod() {
}
}
}
I want to call the wantedMethod() to test it
Here is my…

josephino
- 360
- 4
- 21
6
votes
3 answers
How can I set the JavaScript object name that gets returned in a console.log?
So, first question here - please be gentle.
I'm working on a fairly JavaScript heavy project with a few other developers from various non-web programming backgrounds and we've decided to try and use public and private methods and properties in our…

drewdah
- 91
- 2
- 7
6
votes
1 answer
Can one access private member functions through casting to layout-compatible types?
From the discussion of this question How is access for private variables implemented in C++ under the hood? I posed a variation: instead of accessing a private data member, can one call private member functions through casting and relying on…

TemplateRex
- 69,038
- 19
- 164
- 304