private-methods

Objective-C: Should I declare private methods?

和自甴很熟 提交于 2019-11-28 03:43:52
问题 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 implement it, the app compiles and runs without warning or error. So, should I even bother declaring private methods in class extensions? Why should we have to declare methods anyway? In Java, you don't... neither in Ruby. 回答1: A method definition only

Private Variables and Methods in Python [duplicate]

不想你离开。 提交于 2019-11-27 18:55:02
Possible Duplicate: The meaning of a single- and a double-underscore before an object name in Python Which should I use _foo (an underscore) or __bar (double underscore) for private members and methods in Python? Daniel Kluev Please note that there is no such thing as "private method" in Python. Double underscore is just name mangling: >>> class A(object): ... def __foo(self): ... pass ... >>> a = A() >>> A.__dict__.keys() ['__dict__', '_A__foo', '__module__', '__weakref__', '__doc__'] >>> a._A__foo() So therefore __ prefix is useful when you need the mangling to occur, for example to not

Private module methods in Ruby

血红的双手。 提交于 2019-11-27 16:55:13
I have a two part question Best-Practice I have an algorithm that performs some operation on a data structure using the public interface It is currently a module with numerous static methods, all private except for the one public interface method. There is one instance variable that needs to be shared among all the methods. These are the options I can see, which is the best?: Module with static ('module' in ruby) methods Class with static methods Mixin module for inclusion into the data structure Refactor out the part of the algorithm that modifies that data structure (very small) and make

Private method naming convention [closed]

 ̄綄美尐妖づ 提交于 2019-11-27 11:58:42
问题 Is there a convention for naming the private method that I have called " _Add " here? I am not a fan of the leading underscore but it is what one of my teammates suggests. public Vector Add(Vector vector) { // check vector for null, and compare Length to vector.Length return _Add(vector); } public static Vector Add(Vector vector1, Vector vector2) { // check parameters for null, and compare Lengths Vector returnVector = vector1.Clone() return returnVector._Add(vector2); } private Vector _Add

Unit testing of private methods [duplicate]

扶醉桌前 提交于 2019-11-27 10:59:18
This question already has an answer here: How do I test a private function or a class that has private methods, fields or inner classes? 49 answers I am in the process of writing some unit tests. In particular I want to test some private methods. So far the I have come up with using. #define private public But I am not happy with this as it will destroy all encapsulation from the point of view of the unit test. What methods do you use to unit-test private methods. If the methods are complex enough to warrant testing in isolation, then refactor them into their own class(es) and test via their

When/why to make function private in class?

别来无恙 提交于 2019-11-27 01:34:06
问题 When should i make a function private and why is it good idea? 回答1: You should make a function private when you don't need other objects or classes to access the function, when you'll be invoking it from within the class. Stick to the principle of least privilege , only allow access to variables/functions that are absolutely necessary. Anything that doesn't fit this criteria should be private . 回答2: I usually make the helper functions private . But what is helper seems to be vague. So let me

Unit testing of private methods [duplicate]

≡放荡痞女 提交于 2019-11-26 22:20:01
问题 This question already has an answer here: How do I test a private function or a class that has private methods, fields or inner classes? 51 answers I am in the process of writing some unit tests. In particular I want to test some private methods. So far the I have come up with using. #define private public But I am not happy with this as it will destroy all encapsulation from the point of view of the unit test. What methods do you use to unit-test private methods. 回答1: If the methods are

Private Variables and Methods in Python [duplicate]

强颜欢笑 提交于 2019-11-26 19:39:41
问题 Possible Duplicate: The meaning of a single- and a double-underscore before an object name in Python Which should I use _foo (an underscore) or __bar (double underscore) for private members and methods in Python? 回答1: Please note that there is no such thing as "private method" in Python. Double underscore is just name mangling: >>> class A(object): ... def __foo(self): ... pass ... >>> a = A() >>> A.__dict__.keys() ['__dict__', '_A__foo', '__module__', '__weakref__', '__doc__'] >>> a._A__foo(

Private module methods in Ruby

与世无争的帅哥 提交于 2019-11-26 18:47:34
问题 I have a two part question Best-Practice I have an algorithm that performs some operation on a data structure using the public interface It is currently a module with numerous static methods, all private except for the one public interface method. There is one instance variable that needs to be shared among all the methods. These are the options I can see, which is the best?: Module with static ('module' in ruby) methods Class with static methods Mixin module for inclusion into the data

private method in inheritance in Java

∥☆過路亽.° 提交于 2019-11-26 17:17:51
问题 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){ System.out.print("Over:"+number); } } public class Tester { public static void main(String[] args) { A a=new B(); a.say(12); } } Based on the codes above, I am confused about the inheritance of private method, is the private method inherited from class A to B ? Or the say methods in