private

Parameter vs. Member variables

廉价感情. 提交于 2019-11-30 17:06:42
I've recently been working with someone else's code and I realized that this individual has a very different philosophy regarding private variables and method parameters than I do. I generally feel that private variables should only be used in a case when: The variable needs to be stored for recall later. The data stored in the variable is used globally in the class. When the variable needs to be globally manipulated (something decidedly different from the need to read the variable by every class method). When it will make programming substantially easier. (Admittedly vague, but one has to be

Parameter vs. Member variables

这一生的挚爱 提交于 2019-11-30 16:26:26
问题 I've recently been working with someone else's code and I realized that this individual has a very different philosophy regarding private variables and method parameters than I do. I generally feel that private variables should only be used in a case when: The variable needs to be stored for recall later. The data stored in the variable is used globally in the class. When the variable needs to be globally manipulated (something decidedly different from the need to read the variable by every

Why make class members private?

跟風遠走 提交于 2019-11-30 15:30:11
I've learn C++ for some time, however there is always this question which puzzles me (for years). In school, our lecturers like to declare class variables as private. In order to access it, we have to declare an accessor to access it. Sometimes we even have to make the different classes become "friends" into order to access its elements. My question is: Why make it so troublesome? What is the true rationale behind all the private and protected stuff when we can just make our life as a programmer easier by using public for everything? I was thinking, once the code gets compiled, the end user

Private Constructor in Python

主宰稳场 提交于 2019-11-30 13:07:46
问题 How do I create a private constructor which should be called only by the static function of the class and not from else where? 回答1: How do I create a private constructor? In essence, it's impossible both because python does not use constructors the way you may think it does if you come from other OOP languages and because python does not enforce privacy, it just has a specific syntax to suggest that a given method/property should be considered as private. Let me elaborate... First: the

Are private constants possible in PHP? [duplicate]

两盒软妹~` 提交于 2019-11-30 12:23:42
问题 This question already has answers here : Why doesn't PHP permit private const? (2 answers) Closed 2 years ago . PHP does not allow class Foo { private const my_private_const; but of course allows const my_const; So in effect constants are global because I can access my_const anywhere using Foo::my_const Is there a way to make private constants? 回答1: The answer is a simple "no". PHP doesn't support this concept. The best you can do is a private static variable in the class, which isn't as good

C# Set probing privatePath without app.config?

瘦欲@ 提交于 2019-11-30 11:58:56
I have a C# application, and to organize its files I have some DLL's in a folder called "Data". I want the EXE to check this folder for the DLL's just like how it checks its current directory. If I created a App.Config with this information: <?xml version="1.0" encoding="utf-8" ?> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <probing privatePath="Data" /> </assemblyBinding> </runtime> </configuration> It works without a problem. I do not want to have an App.Config. Is there a way to set the probing path without using an app.config? You can do it for new

Inaccessible type due to private inheritance

拈花ヽ惹草 提交于 2019-11-30 11:48:23
g++ is denying me access to a type, just because it happens to be a private grand-father. Does this make sense? struct A {}; struct B : private A {}; struct C : B { void foo(A const& a) {} }; Compiling this yields: 1:10: error: ‘struct A A::A’ is inaccessible 6:12: error: within this context My point is: I never wanted to access A as an ancestor. In fact, if A is a private ancestor of B , shouldn't this be completely invisible to anybody but B (i.e. C )? Of course, I could use protected inheritance but in my case it doesn't really make sense. This is due to the injected class name from A

C# override public member and make it private

浪子不回头ぞ 提交于 2019-11-30 11:46:10
Possible? Can you change the access of anything to anything else? No, you can hide a public member with a private method in a subclass, but you cannot override a public member with a private one in a subclass. And, in actually, it's not just a public/private thing, this applies to narrowing the access in general. Revised : By hiding with a more restrictive access - in this case private access - you will still see the base class member from a base-class or sub-class reference, but it would defer to the new method when available from the new access level. So in general, when you hide, the hide

meteor private subdirectory

…衆ロ難τιáo~ 提交于 2019-11-30 11:22:04
I was recently made aware of meteor private subdirectories. According to the docs: "The private subdirectory is the place for any files that should be accessible to server code but not served to the client, like private data files." I am a newbie at web development in general, so my question is what is the advantage of having these files within the private subdirectory vs. just in the server subdirectory itself? Is the server subdirectory not private - e.g. I have some email templates defined and my email login information is set up in a startup function in the server subdirectory, are these

The reason for encapsulation [closed]

时光毁灭记忆、已成空白 提交于 2019-11-30 10:01:52
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I've read some things about this, I even found similar question, but it didn't really answer this. For me it seems that privatizing something only makes my life so much harder when I need to find a private variable in a class to use it elsewhere. So what is would the problem be if everything was public? Would it