Questions tagged [private-methods]

285 questions
25
votes
2 answers

Is there a way to declare public and private methods for S4 Reference Classes?

Up-front: I am aware that R is a functional language, so please don't bite ;-) I've had great experiences with using an OOP approach for a lot of my programs. Now, I'm wondering if there's a way to make a distinction between public and private…
Rappster
  • 12,762
  • 7
  • 71
  • 120
24
votes
6 answers

assign value of readonly variable in private method called only by constructors

C# compiler gave me the following error CS0191: A readonly field cannot be assigned to (except in a constructor or a variable initializer) Do I have to move the code (in my private function) into the constructor? That sounds awkward. Note that the…
tom
  • 14,273
  • 19
  • 65
  • 124
23
votes
3 answers

Error: Attempt to call private method

Coming from a long history of C-style syntax and now trying to learn Ruby (on Rails), I've been having my share of issues with its idioms and such, but today I hit one I didn't expect to have a problem with and I can't see whatever it is that must…
Rob Wilkerson
  • 40,476
  • 42
  • 137
  • 192
21
votes
5 answers

Partitioning struct into private and public sections?

In C++ and Java, data structures can have private, public and protected regions. I'd like to port this concept to a C language program I am writing. Are there any idioms for implementing private or protected function pointers and data fields in a…
Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
19
votes
3 answers

Pass parameters to PrivateObject method

I am trying to unit test private method. I saw example below on this question Class target = new Class(); PrivateObject obj = new PrivateObject(target); var retVal = obj.Invoke("PrivateMethod"); Assert.AreEqual(retVal); My private method has 2 ref…
eomeroff
  • 9,599
  • 30
  • 97
  • 138
18
votes
6 answers

Invoking a private method via JMockit to test result

Am using JMockit 1.1 and all I want to do is invoke a private method and test the return value. However, I am having trouble understanding exactly how to do this from the JMockit De-Encapsulation example. The method I am trying to test is the…
Robert Mark Bram
  • 8,104
  • 8
  • 52
  • 73
14
votes
1 answer

Is Ruby private method accessible in sub class?

I have code as follows: class A private def p_method puts "I'm a private method from A" end end class B < A def some_method p_method end end b = B.new b.p_method # => Error: Private method can not be called b.some_method # =>…
Venkat Ch
  • 1,168
  • 2
  • 17
  • 37
14
votes
6 answers

C Private Variables Get and Set methods

I am working in C, and have some variables that I don't want to be global, but I do want to have get and set methods for them that can be accessed "Globaly" outside of the file. I am used to doing this in Java, but C is very different in this…
Reid
  • 4,376
  • 11
  • 43
  • 75
13
votes
11 answers

C# Private members visibility

We have a Student class in our business model. something struck me as strange, if we are manipulating one student from another student, the students private members are visible, why is this? class Program { static void Main(string[] args)…
Aran Mulholland
  • 23,555
  • 29
  • 141
  • 228
13
votes
5 answers

Ruby on Rails Private Methods?

If I'm writing a private method, does rails think that every method under the word private is going to be private? or is it supposed to be only private for the first method? private def signed_in_user redirect_to signin_url, notice:…
hellomello
  • 8,219
  • 39
  • 151
  • 297
12
votes
2 answers

How to configure eslint for ES6 class with private methods correctly?

I was writing ES6 class with private properties/methods in vue project. And using eslint to lint the code. Below is the example class: class TestClass { constructor(value) { this.#privateProperty = value …
Sven Doo
  • 133
  • 1
  • 5
10
votes
6 answers

What is the best practice for naming private and static private methods in C#?

I'm trying to figure out what is the smartest way to name private methods and private static methods in C#. Background: I know that the best practice for private members is underscore-prefix + camelcase. You could argue this with me, but trust me…
Mark Rogers
  • 96,497
  • 18
  • 85
  • 138
10
votes
4 answers

Access inner function variables in Javascript

In many frameworks, internal function variables are used as private variables, for example Raphael = (function(){ var _private = function(a,b) {return a+b;}; var _public = function(a) {return _private(a,a);} var object =…
Elazar Leibovich
  • 32,750
  • 33
  • 122
  • 169
9
votes
3 answers

objective-c private versus public methods and declaration in header or not?

What is the best practice approach to private methods in objective-c. That is a method that's only going to be used the class as a helper method. In particular what's not clear to me is: Is there a need to have the method specified in the header…
Greg
  • 34,042
  • 79
  • 253
  • 454
9
votes
3 answers

Private interface methods are supported

Private interface methods are supported by Java 9. This support allows non-abstract methods of an interface to share code between them. Private methods can be static or instance. Can private methods of an interface be abstract or default? May I ask…
Neha Gangwar
  • 670
  • 9
  • 14
1
2
3
18 19