private-members

Breaking public member functions into lots of private member functions

When I write a class's public member function that does several things, like.. void Level::RunLogic(...); In that function I find myself splitting it up into several private member functions. There's no point in splitting the public member function up into several functions because you wouldn't do one thing without the other, and I do...

How to get the private member value in C#

Hi, I wanna get the value of a private member, so I wrote the following: var f = e. GetType(). GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly)[0]; object o = f.FieldType.GetProperty("Ro...

C# Private members visibility

We have a Student class in our business model. something struck me as strange, if we are manipulating one student from another student, the students private members are visible... this strikes me as a little indecent :) class Program { static void Main(string[] args) { Student s1 = new Student(); Student s2 =...

How to make instance variables private in Ruby?

Is there any way to make instance variables "private"(C++ or Java definition) in ruby? In other words I want following code to result in an error. class Base def initialize() @x = 10 end end class Derived < Base def x @x = 20 end end d = Derived.new ...

How to deal with private member accessor and collections?

I have a class hierachy like this public class A { protected class B { String Name { get; set; } } protected class C : KeyedCollection<String, B> { // ... } protected C Collection { get; } // ... public A Copy () { // Creates a deep copy of this instance. } } N...

Javascript private methods -- what is the memory impact?

I'm working on a bit of code where I'm attempting to hide some private variables inside closures. The thing is the environment is fairly constrained in terms of memory, so I'm also concerned with keeping the overall footprint of the classes low. What is the impact of using closures to hide private instance variables and methods when com...

create object of the same class: javascript prototype, private members, inheritance

Some code may say more than a thousand words: /** * Represents an amount of a resource * @param {number} amount * @param {string} type */ function Resource(amount, type) { var nAmount = amount; var sType = type; if (amount < 0) { throw new IllegalArgumentException("amount has to be positive"); } /** ...

Purpose of private members in a class

What are the purposes of having private/protected members of a class/structure in object-oriented programming? What's the harm in having all members be public? ...

How to implement a private virtual function within derived classes?

Hi, I know why I want to use private virtual functions, but how exactly can I implement them? For example: class Base{ [...] private: virtual void func() = 0; [...] }; class Derived1: public Base{ void func() { //short implementation is ok here } }; class Derived2: public Base{ void func(); //long implementation elsewhere ...

(C#) iterate over read-only private collection member

I have a class which has two HashSet<String> collections as private members. Other classes in my code would like to be able to iterate over those HashSets and read their contents. I don't want to write a standard getter because another class could still do something like myClass.getHashSet().Clear(); Is there any other way to expose t...

Hiding members in a C struct

I've been reading about OOP in C but I never liked how you can't have private data members like you can in C++. But then it came to my mind that you could create 2 structures. One is defined in the header file and the other is defined in the source file. // ========================================= // in somestruct.h typedef struct { ...

Private members when extending a class using ExtJS

I have done some research on the ExtJS forum regarding private methods and fields inside a extended class, and I couldn't find any real answer to this. And when I say an extended class I mean something like this: Ext.ux.MyExtendedClass = Ext.extend(Ext.util.Observable, { publicVar1: 'Variable visible from outside this class', c...

UINavigationController crash because of pushing and poping UIViewControllers

My question is related to my discovery of a reason for UINavigationController to crash. So I will tell you about the discovery first. Please bare with me. The issue: I have a UINavigationController as as subview of UIWindow, a rootViewController class and a custom MyViewController class. The following steps will get a Exc_Bad_Access, 1...

Is private members hacking a defined behaviour ?

Hi, Lets say I have the following class: class BritneySpears { public: int getValue() { return m_value; }; private: int m_value; }; Which is an external library (that I can't change). I obviously can't change the value of m_value, only read it. Even subclassing BritneySpears won't work. What if I define the following ...

iPhone static libraries: How to hide instance variable

I'm creating a static library to share using the following guide: http://www.amateurinmotion.com/articles/2009/02/08/creating-a-static-library-for-iphone.html In one of the functions, I return a "SomeUIView" which is a subclass of UIView and is defined in the public header, however I don't want to expose the internal instance variable o...

In what circumstances are instance variables declared as '_var' in 'use fields' private?

I'm trying to understand the behavior of the fields pragma, which I find poorly documented, regarding fields prefixed with underscores. This is what the documentation has to say about it: Field names that start with an underscore character are made private to the class and are not visible to subclasses. Inherited fields can be overri...

Flex: How do you list private attributes of a class?

Hi, I try to serialize objects with their private attributes, in Flex. The introspection API does not seem to allow it: "The describeType() method returns only public members. The method does not return private members of the caller's superclass or any other class where the caller is not an instance." Is there another way for an insta...

In C++, does adding a friend to a class change its memory layout ?

Also, does it matter where in the class you declare the friend ? Does it matter if you add a friend class or a friend function ? ...

Private Variable Instantiation: When Defined or Within Constructor?

I don't know if this has been asked before, but we're having a discussion about it today at my job. Should private variables (that are shared/static) be instantiated when they are dimensioned/defined, or is it a better practice to do this inside of a constructor? For example, this seems perfectly fine to me... Public Class IpCam ...

C++ alter private member variable from static member function

I noticed while reading through my code that I have a static member function which alters a private member of its class through a pointer to an instance of said class. It compiles and functions without issue, but I just wanted to know whether or not it was kosher to edit a private variable in this way, from a member but static function,...