Private Variables and Methods in Python [duplicate]

Please note that there is no such thing as “private method” in Python. Double underscore is just name mangling: >>> class A(object): … def __foo(self): … pass … >>> a = A() >>> A.__dict__.keys() [‘__dict__’, ‘_A__foo’, ‘__module__’, ‘__weakref__’, ‘__doc__’] >>> a._A__foo() So therefore __ prefix is useful when you need the mangling to occur, for … Read more

Why do we actually need Private or Protected inheritance in C++?

It is useful when you want to have access to some members of the base class, but without exposing them in your class interface. Private inheritance can also be seen as some kind of composition: the C++ faq-lite gives the following example to illustrate this statement class Engine { public: Engine(int numCylinders); void start(); // … Read more

When would I want to make my private class static?

I think this is a good starting point: http://java67.blogspot.fi/2012/10/nested-class-java-static-vs-non-static-inner.html 1) Nested static class doesn’t need reference of Outer class but non static nested class or Inner class requires Outer class reference. You can not create instance of Inner class without creating instance of Outer class. This is by far most important thing to consider while … Read more

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

There are at least two more options. I’ll list out some other options you should consider by explaining a certain situation. Option 4: Consider refactoring your code so that the part you want to test is public in another class. Typically when you’re tempted to test a class’s private method, it’s a sign of bad … Read more

Get all private fields using reflection

It is possible to obtain all fields with the method getDeclaredFields() of Class. Then you have to check the modifier of each fields to find the private ones: List<Field> privateFields = new ArrayList<>(); Field[] allFields = SomeClass.class.getDeclaredFields(); for (Field field : allFields) { if (Modifier.isPrivate(field.getModifiers())) { privateFields.add(field); } } Note that getDeclaredFields() will not return … Read more

Protected and private methods in Rails

For models, the idea is that the public methods are the public interface of the class. Public methods are intended to be used by other objects, while protected/private methods are to be hidden from the outside. This is the same practice as in other object-oriented languages. For controllers and tests, just do as you please. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)