private-members

How to instantiate PrivateType of inner private class

I was trying to setup a unit test for a private inner class, but had very little success: namespace Stats.Model { public class DailyStat { private class DailyStatKey // The one to test { private DateTime date; public DateTime Date { get { return date; } set { date = value.Date; } } ...

Javascript: should I be hiding my implementations?

As a C# programmer, I have a bit of a habit of making things private that can and should be private, and I always get a weird feeling when a JS type exposes all its private parts to me (and that feeling is not 'aroused'). Say I have a type that has a draw method, which internally calls drawBackground and drawForeground, which make no sen...

Does declaring a variable as "private" in C# protect the memory in windows from being accessed by a memory scanner?

My workmate always tells me that if we declare anything as "public" then it is dangerous because then any program can access that memory and that the solution is to use the "private" access modifier. I am wondering if this is infact true. ...

Private Variables and Methods in Python

Which should I use _foo (an underscore) or __bar (double underscore) for private members and methods in Python? ...

Maintaining private set and public get access to property in ViewModel and Model

So I currently have a a class like this in my ViewModel: namespace ViewModel { public sealed class MyClass { public static bool IsInMode { get; private set; } } } The way our assemblies are setup is that the view can access the viewmodel, and the model, but the viewmodel can only access the model, ...

Assigning Gettext String to Class Member

I'm making a site that will be translated into x languages. All strings must be localized. There are occasions when I need to display a language name, country name or other information that has been retrieved from a database. The data being dealt with in this way will seldom be changed - as above I'm talking about language names, count...

Access to private inherited fields via reflection in Java

I founded a way to get inherited members via class.getDeclaredFields(); and acces to private members via class.getFields() But i'm looking for private inherited fields. How can i achieve this? ...

Declaring private member variables

I've started learning Objective-C a few weeks ago and I still don't understand how to manage the encapsulation of a class correctly. What is the best way to declare a private member variable in a class? It seems that setting the right getter/setter for your member variable with "@property" is the right way to go, more than just declarin...

Why do we need static private array to initialize other non static private array fields?

If you take a look inside Stack<T> class from .NET 4.0, you will notice that there is an "emptyArray" private static field which is used inside constructors to initialize a real "array" private field. private T[] array; private static T[] emptyArray; private int size; private int version; static Stack() { Stack<T>.emptyArray = new ...

Using reflection to change implementation

My boss regards himself as a OOP Guru where as I consider him as a hobbyist programmer. He handles our Sage development, adding custom requirements to our clients Sage installations. He recently has got very excited by reflection, he is reflecting on Sage's assemblies in code and changing private members and event handlers. I thought t...

PHP: Calling a private method from within a class dying badly

So this might sound a little convoluted. Fingers crossed I come across clearly. I'm working in an MVC framework in PHP. I load a controller /report/index which calls to a helper <? class ReportController extends Controller { public function index() { $foo = MainReport::get_data($_REQUEST); } } ?> ...

C++ passing reference to class' private variable - compiler issue?

Is the passing by reference of a private variable in a class to be directly changed outside that class acceptable practice? Or is this something that the compiler 'should' pick up and prevent? Example: //------------------------------------------- class Others { public: Others() {}; void ChangeIt(string &str) { str = "Changed by Othe...

Private template classes/structs visibility

I don't understand why in the following code, I am allowed to create the function print_private_template while the compiler complains about print_private_class: #include <cstdio> class A { private: template <unsigned T> struct B { }; struct C { }; public: templ...

Beginner C++ Using accessors / getters to pull data from a private member variable (2D array)

Hi guys, total noob here with about 2 months of C++ experience (no other background) so go easy on me. I am writing a battleship game for a programming assignment. The game grid is 15X20 and I am trying to have the grid as a private member variable of the class player. My question is: If the class player has a private member variab...

Access private elements of object of same class

Is this legal? If not, will the following code allow this? class Foo { friend class Foo; } ...

[Opinion] Accessing private variables when there's a getter/setter for them

I have a question about righteous way of programming in Python... Maybe there can be several different opinions, but here it goes: Let's say I have a class with a couple of private attributes and that I have implemented two getters/setters (not overloading __getattr__ and __setattr__, but in a more “Java-tistic” style): class MyClass: ...

MSIL - how do you invoke a private method from MSIL?

I'm writing a "weak event factory" - code which converts any Delegate into a new delegate with an identical signature, but with implementing a WeakReference on the target. I'm using MSIL to avoid calls to Delegate.CreateDelegate (which performance have shown to be slow). The weak reference delegates work perfectly as long as the underly...

Delphi: writing to the private ancestor's field in descendant class

I need to fix a third-party component. This component's class has private variable which is actively used by its descendants: TThirdPartyComponentBase = class private FSomeVar: Integer; public ... end; TThirdPartyComponent = class (TThirdPartyComponentBase) protected procedure Foo; virtual; end; procedure TThirdPartyComponent.F...