Questions tagged [private-methods]

285 questions
3
votes
6 answers

How to use a object whose copy constructor and copy assignment is private?

In reading TCPL, I got a problem, as the title refered, and then 'private' class is: class Unique_handle { private: Unique_handle& operator=(const Unique_handle &rhs); Unique_handle(const Unique_handle &rhs); public: //... }; the using…
coanor
  • 3,746
  • 4
  • 50
  • 67
3
votes
3 answers

functional test for rails controller private method

I have a private method in my controller. which is used for some database update. this method i am calling from another controller method. and it works fine. But when i am trying to write a test case for that method then It is tripping on accessing…
mohit
  • 1,913
  • 3
  • 16
  • 23
3
votes
3 answers

Allow operator= being used only between objects of the same class?

I have a class hierarchy and I want to forbid doing this: Foo *f = new Foo(); Bar *b = new Bar(); f = b; where Foo is a superclass of Bar. Doing this would slice the Bar part of the object. I know you can solve this by making operator= private,…
3
votes
5 answers

Unit testing private methods seems to make the whole solution easier

Let's suppose there is an utility class (no data) with one complex (as in, hard-to-test) public method. It uses random number generation, return large arrays of data and that fun stuff. However, if you implement it in small private methods, every…
user1288851
  • 467
  • 1
  • 3
  • 8
3
votes
4 answers

Should controllers avoid private functions at CakePHP?

I was wondering if controllers at CakePHP should not contain any private function which is not accessible by URL. Sometimes some functions such as add or delete can be so large that I prefer to divide them. Should I put that functions inside the…
Alvaro
  • 40,778
  • 30
  • 164
  • 336
2
votes
1 answer

Private Method Implementation

This question is mostly curiosity than anything else. But I currently place all my private methods first in my @implementation so that I can avoid creating an a separate category in my .m file for those methods. As long as the private method was…
2
votes
2 answers

How to update internal config from outside the namespace?

I've got a javascript file as follows (function (rpc) { rpc.loadHomeBanner = rpc_loadHomeBanner; function rpc_loadHomeBanner(){ // AN is used by Sencha Animator as an Animation variable rpc.AN ={}; …
Chase Florell
  • 46,378
  • 57
  • 186
  • 376
2
votes
1 answer

Why is JavaScript private method accessible from console.log

I wrote a simple code: const secure = new class { #privateProperty = 4; #privateMethod() { console.log( 'The property ' + this.#privateProperty + ' should not be accessible outside this class' ); } } If it is immediately…
2
votes
1 answer

Dart: testing private methods by accessing mock's property

I'm trying to get a mocked object property. During the initialization, 'child' class is getting a reference to a parent's private function. I'd like to catch this reference during testing to check parent's private method. This is a simplified…
Ensei Tankado
  • 270
  • 2
  • 12
2
votes
1 answer

How to add method and intercept private fields from a different class

I am trying to introduce a Shape class as a parent interface for the classes Circle and Rectangle. I have to implement getName() method that will return Circle for the Circle object and Rectangle for the Rectangle object. Also, I have to override…
Jennifer
  • 115
  • 9
2
votes
2 answers

Unit Testing Private Methods in Unity Test Runner

I'd like to do a unit test for my private methods in C#. Since the methods are private, they are not accessible from the test environment.
2
votes
2 answers

How to avoid overtesting of a private method's behavior?

Given that: Testing private methods is not a good practice. An interface with many public methods is not a good practice either. Suppose I have the following code: module RedisHelper private def key_for(id) [prefix, id].join('-') end …
user1519240
  • 2,186
  • 1
  • 22
  • 20
2
votes
1 answer

Accessing rails private/protected methods through javascript or jquery

I know I can access public controller actions by doing something like this with jquery: $("#stuff").load("/controller/action"); But how do I access the private/protected actions in a controller using jquery or javascript?
2
votes
2 answers

Objective-C call hidden methods

The following is an example of hidden method in Objective-C: MyClass.m #import "MyClass.h" @interface MyClass (Private) -(void) privateMethod:(NSString *)arg1 and: (NSString*)arg2; @end @implementation MyClass -(void) publicMethod { …
Kami
  • 5,959
  • 8
  • 38
  • 51
2
votes
1 answer

reduce the access level of a function in a derived class

Is there any possibility to reduce the access level of a function in a derived class in PHP? example (... means more code) class foo { public function myFunction() { ... } public function myOtherFunction() { ... } } class bar extends foo { …
inquam
  • 12,664
  • 15
  • 61
  • 101