private

Unit testing private code [duplicate]

孤街醉人 提交于 2019-11-29 01:05:58
问题 This question already has answers here : Unit testing private methods in C# (10 answers) Closed 2 years ago . I am currently involved in developing with C# - Here is some background: We implement MVP with our client application and we have a cyclomatic rule which states that no method should have a cyclomatic complexity greater than 5. This leads to a lot of small private methods which are generally responsible for one thing. My question is about unit testing a class: Testing the private

What exactly is a Private API, and why will Apple reject an iOS App if one is used?

萝らか妹 提交于 2019-11-28 23:33:28
问题 I've read several articles about this, and I just want to see if I understand this correctly: Apple will reject your app if you use a Private API... What is the main difference between a "Private API" and a "Non-private API?" Are the "Non-private" APIs only the APIs provided and verified by Apple? Isn't an API just a way of interacting with a Framework, and a Framework is just a set of encapsulated classes/headers that people can use for trivial purposes? Wouldn't this mean that I cannot

Why can a “private” method be accessed from a different instance?

雨燕双飞 提交于 2019-11-28 20:47:49
Although, this is a very basic code, it seems there is something fundamentally flawed in Java, or the JVM used by the Eclipse IDE I have used to run the code. The code runs even though it should not (I think)! The code in A.java simply displays "Hello, I am A!" Here it is: import java.lang.*; import java.util.*; class A { private void methodA() {System.out.println("Hello, I am A!");} public static void main(String[] args) { A a = new A(); a.methodA(); } } I do not understand why, after creating an instance of class A, main() succeeds in running a private method of class A on that instance. Yes

Are there good reasons for 'private' to work the way it does in Ruby?

人盡茶涼 提交于 2019-11-28 18:59:53
问题 It took me a while to understand how private methods work in Ruby, and it really strikes me as being very awkward. Does anyone know if there are good reasons for private methods to be handled the way they are? Is it just historic reasons? Or implementation reasons? Or are there good solid logical reasons (ie. semantic)? For example: class Person private attr_reader :weight end class Spy < Person private attr_accessor :code public def test code #(1) OK: you can call a private method in self

Quick Java question about private static final keywords for fields

℡╲_俬逩灬. 提交于 2019-11-28 18:37:50
I'm declaring a field: private static final String filename = "filename.txt"; First, does the order of private static final matter? If not, is there a standard accepted sequence or convention? Second, the filename in my application is fixed. Is this the best was to store its value? I use Checkstyle with Eclipse, which results in a warning if the declaration is in a different order to the one you've specified, citing the Java Language Specification (JLS). For example, private final static String filename = "filename.txt"; results in 'static' modifier out of order with the JLS suggestions. They

Reasons to use private instead of protected for fields and methods

本小妞迷上赌 提交于 2019-11-28 17:28:09
This is a rather basic OO question, but one that's been bugging me for some time. I tend to avoid using the 'private' visibility modifier for my fields and methods in favor of protected . This is because, generally, I don't see any use in hiding the implementation between base class and child class, except when I want to set specific guidelines for the extension of my classes (i.e. in frameworks). For the majority of cases I think trying to limit how my class will be extended either by me or by other users is not beneficial. But, for the majority of people, the private modifier is usually the

Why would a virtual function be private?

别说谁变了你拦得住时间么 提交于 2019-11-28 17:03:55
I just spotted this in some code: class Foo { [...] private: virtual void Bar() = 0; [...] } Does this have any purpose? (I am trying to port some code from VS to G++, and this caught my attention) See this Herb Sutter article as to why you'd want to do such a thing. This is a pure virtual function that happens to be private. This makes it so that a derived class must implement the method. In this case Bar. I think you may be confused b/c this is done to create "interfaces" in C++ and a lot of times people think of these as public. There are cases where you may want to define an interface that

Hiding private data members? (C++)

妖精的绣舞 提交于 2019-11-28 16:59:58
Is there a way to hide private data members of a C++ class away from its users, in the cpp file? I think of the private members as part of the implementation and it seems a little backwards to declare them in the header file. Kristopher Johnson The "pimpl" idiom is how this is generally handled. See http://www.gotw.ca/gotw/024.htm http://www.gotw.ca/gotw/028.htm http://herbsutter.com/gotw/_100/ (updated for C++11) you want to use something like the PIMPL idiom http://en.wikipedia.org/wiki/Opaque_pointer See Pimpl Idiom The classic way to do this is with a proxy pointer to an internal class

What is the best way of testing private methods with GoogleTest? [closed]

江枫思渺然 提交于 2019-11-28 15:38:28
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . I would like to test some private methods using GoogleTest. class Foo { private: int bar(...) } GoogleTest allows a couple of ways of doing this. OPTION 1 With FRIEND_TEST : class Foo { private: FRIEND_TEST(Foo, barReturnsZero); int bar(...); } TEST(Foo, barReturnsZero) { Foo

What's the best way to unit test protected & private methods in Ruby?

纵然是瞬间 提交于 2019-11-28 15:14:11
What's the best way to unit test protected and private methods in Ruby, using the standard Ruby Test::Unit framework? I'm sure somebody will pipe up and dogmatically assert that "you should only unit test public methods; if it needs unit testing, it shouldn't be a protected or private method", but I'm not really interested in debating that. I've got several methods that are protected or private for good and valid reasons, these private/protected methods are moderately complex, and the public methods in the class depend upon these protected/private methods functioning correctly, therefore I