private-members

Private members when extending a class using ExtJS

风格不统一 提交于 2019-12-02 15:19:17
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', constructor: function(config) { this.addEvents("fired"); this.listeners = config.listeners; }, // to show that I need to use the base class publicMethod1: function() { return 'Method which can be called form everywhere'; }, publicMethod2: function() { return this

Is it possible to call a method from main if it is private? If not, how would it be possible?

我的未来我决定 提交于 2019-12-02 13:36:27
I am trying to get this program to start running but currently I just get errors. I am not sure how to get this to work. If I change the class SavingsAccount to public it should be okay, but I am required to keep it as is. The problem is in the main function. #include <iostream> #include <iomanip> #include <string> using namespace std; class SavingsAccount { int accountType; string ownerName; long ssn; double accountClosurePenaltyPercent, accountBalance; void Information(); inline double AccountClosureLoss() { return (accountBalance * accountClosurePenaltyPercent); } void OutputInformation();

Why do we declare Private variables in Java

最后都变了- 提交于 2019-12-02 13:21:43
I'm confused because all I keep hearing is that Private variables in Java are supposed to protect the code or the variable. But if anybody has access to the code, then it makes no difference if it is private, they can still change it. So how is it considered protected when anybody who has access to the code can change it. When programmers talk about accessing a variable, they mean accessing its value when the program runs. Protecting the code from changes is another matter entirely and requires human processes rather than syntax of a programming language. Making a variable private "protects"

Best Practice on local use of Private Field x Property

爱⌒轻易说出口 提交于 2019-12-02 04:52:36
问题 When inside a class you have a private fiels and expose that field on a public property, which one should I use from inside the class? Below you is an example on what I am trying to find out. Should manioulate the Private Field _Counter or the Property Counter? Public Class Test Private _Counter As Integer Public Property Counter() As Integer Get Return _Counter End Get Set(ByVal value As Integer) _Counter = value End Set End Property Private Sub Dosomething() 'What is the best practice?

Best Practice on local use of Private Field x Property

帅比萌擦擦* 提交于 2019-12-02 02:18:42
When inside a class you have a private fiels and expose that field on a public property, which one should I use from inside the class? Below you is an example on what I am trying to find out. Should manioulate the Private Field _Counter or the Property Counter? Public Class Test Private _Counter As Integer Public Property Counter() As Integer Get Return _Counter End Get Set(ByVal value As Integer) _Counter = value End Set End Property Private Sub Dosomething() 'What is the best practice? 'Direct access to private field or property? 'On SET _Counter += 1 'OR Me.Counter += 1 'On Get Console

Private template classes/structs visibility

旧街凉风 提交于 2019-12-01 22:06:20
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: template <unsigned T> B<T> getAb() { return B<T>(); } C getAc() { return C(); } }; template<unsigned T> void print_private_template(const A::B<T> &ab) { printf("%d\n", T); } void print_private_class(const A::C &ac) { printf("something\n"); } int main(int, char**) { A a; print_private_template(a.getAb<42>()); print_private_class(a.getAc());

Using Moq to verify execution of private methods

那年仲夏 提交于 2019-12-01 18:02:54
I want to test the following logic (this is obviously a stripped-down version of my method): public void myPublicMethod(params) { if(some_condition) privateMethod1(); else privateMethod2(); } I have all of the other dependencies in the method mocked out, and I've set this up so that I can guarantee that some_condition is true. What I want to do is verify that my privateMethod1() is called exactly once, and privateMethod2() is not called at all. Is this possible to do with Moq? Here are some notes on the issue: privateMethod1() and privateMethod2() are within the same class as myPublicMethod,

Using Moq to verify execution of private methods

ぐ巨炮叔叔 提交于 2019-12-01 17:44:27
问题 I want to test the following logic (this is obviously a stripped-down version of my method): public void myPublicMethod(params) { if(some_condition) privateMethod1(); else privateMethod2(); } I have all of the other dependencies in the method mocked out, and I've set this up so that I can guarantee that some_condition is true. What I want to do is verify that my privateMethod1() is called exactly once, and privateMethod2() is not called at all. Is this possible to do with Moq? Here are some

Java setting private fields inside constructors

这一生的挚爱 提交于 2019-12-01 16:56:01
Common design practice is to make instance variables private and have public getters and setters to access them. But many times I have seen code samples on the internet that have constructors that assign values directly to the private instance variable instead of using the setters inside constructors. Am I missing something? public class Person{ private String name; public Person(String name){ //is this right, seems like the whole encapsulation purpose is defeated this.name = name; //shouldn't this be used setName(name); } public String getName(){ return this.name; } public void setName(String

Is private member hacking defined behaviour?

China☆狼群 提交于 2019-12-01 15:39:49
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 deriving from BritneySpears won't work. What if I define the following class: class AshtonKutcher { public: int getValue() { return m_value; }; public: int m_value; }; And then do: BritneySpears b; // Here comes the ugly hack AshtonKutcher* a = reinterpret_cast<AshtonKutcher*>(&b); a->m_value = 17; // Print out the value std::cout << b.getValue() << std::endl;