private

Private class unit tests

左心房为你撑大大i 提交于 2019-12-22 04:51:11
问题 How to unit test private (means with package visibility) classed in java? I have a package, only one class is public in this package, other classes are private. How to cover other classed with unit tests? I would like to include unit tests in resting jar. 回答1: Create the unit test class in the same package. For example, If com.example.MyPrivateClass located in src/main/java/com/example/MyPrivateClass.java Then the test class will be in same package com.example.MyPrivateClassTestCase and will

Truly Private Variables in Python 3

本秂侑毒 提交于 2019-12-22 04:30:27
问题 So I know the way to make a variable "private" in python like this: class Foo: def __init__(self): self.__private = 'bar' This "works" and doesn't, as shown below: foo = Foo() '__private' in vars(foo) #False '_Foo__private' in vars(foo) #True Now, I understand this is the way to make private variables in python and I like this way. It allows you to mangle names so that no subclasses accidentally override this (because it begins with the class's name), and that nobody will accidentally use it.

Grant access to private constructor without friends?

梦想与她 提交于 2019-12-21 04:35:10
问题 I am working on some code, where I encountered a situation similar to this one: struct Bar; struct Foo{ friend struct Bar; private: Foo(){} void f(){} void g(){} }; struct Bar { Foo* f; Bar() { f = new Foo();} ~Bar() { delete f;} }; int main(){ Bar b; } I would prefer to have Bar not as friend of Foo , because besides Foo s constructor Bar does not need access to any of Foo s private methods (and thus should not have access). Is there a way to allow only Bar to create Foo s without making

“Private” struct members in C with const

扶醉桌前 提交于 2019-12-21 04:10:36
问题 In order to have a clean code, using some OO concept can be usefull, even in C. I often write modules made of a pair of .h and .c files. The problem is that the user of the module have to be careful, since private members don't exist in C. The use of the pimpl idiom or abstract data types is ok, but it adds some code and/or files, and requires a heavier code. I hate using accessor when I don't need one. Here is a idea wich provides a way to make the compiler complain about invalid access to

Private and public variables to a backbone view

不想你离开。 提交于 2019-12-21 03:53:33
问题 In a backbone view where would you put your private variables and your public. Right now I have something like this: myView = Backbone.View.extend({ initialize: function(options){ this.myPublic = "I'm public"; } }); I tried adding a var myPrivate before the initialize method but it threw an error. Where would private variables that are only used within the view go? 回答1: I suggest you use the initialize method as a closure around all other methods. I think this will give you behaviour more

C++: Why must private functions be declared?

☆樱花仙子☆ 提交于 2019-12-21 03:24:10
问题 Why do classes in C++ have to declare their private functions? Has it actual technical reasons (what is its role at compile time) or is it simply for consistency's sake? 回答1: I asked why private functions had to be declared at all, as they don't add anything (neither object size nor vtable entry) for other translation units to know If you think about it, this is similar to declaring some functions static in a file. It's not visible from the outside, but it is important for the compiler itself

importing private frameworks in Xcode

本秂侑毒 提交于 2019-12-20 23:59:41
问题 I am a novice iPhone programmer I want to use some of the functions in the private framework https://github.com/kennytm/iphone-private-frameworks The function that I want to use is in 'SpringBoard' So I downloaded 'SpringBoard' folder in that github repo. And created a subdirectory called "Headers" in 'SpringBoard' and put all the header files in that folder. And renamed 'SpringBoard' to 'SpringBoard.framework' and copied it to /Developer/Platforms/(iPhoneOS_and_iPhoneSimulator)/sdks/System

How can I declare a private property within a named category?

故事扮演 提交于 2019-12-20 12:28:35
问题 I know about the possibility of declaring private properties on a class by putting them inside an unnamed category on that class declared in the implementation ( .m ) file of that class. That's not what I want to do. I'm dealing with a named category on a class that adds some functionality to that class. For this functionality, it would help me very much to have a private property to use in my category - so the usual way of achieving this (described above) doesn't seem to work for me. Or does

Private class declaration [duplicate]

半世苍凉 提交于 2019-12-20 10:08:57
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Java: Why can we define a top level class as private? Why can't we declare a private outer class? If we can have inner private class then why can't we have outer private class...? 回答1: Private outer class would be useless as nothing can access it. See more details: Java: Why can we define a top level class as private? 回答2: To answer your question: If we can have inner private class then why can't we have outer

access private members in inheritance

怎甘沉沦 提交于 2019-12-20 09:30:25
问题 I have a class A, which have a field val declared as private. I want to declare a class B, that inherit from A and have an access to val. Is there a way to do it on C++? I want to do it because I need to overload some functions of A, without changing A code at all. Thanks. 回答1: Quick answer: You don't. Thats what the protected key-word is for, which you want to use if you want to grant access to subclasses but no-one else. private means that no-one has access to those variables, not even