protected

Should protected attributes always be banned?

对着背影说爱祢 提交于 2019-12-03 16:14:27
问题 I seldom use inheritance, but when I do, I never use protected attributes because I think it breaks the encapsulation of the inherited classes. Do you use protected attributes ? what do you use them for ? 回答1: In this interview on Design by Bill Venners, Joshua Bloch, the author of Effective Java says: Trusting Subclasses Bill Venners: Should I trust subclasses more intimately than non-subclasses? For example, do I make it easier for a subclass implementation to break me than I would for a

@protected in Objective-C

百般思念 提交于 2019-12-03 15:57:09
I have a simple class: #import <UIKit/UIKit.h> #import <CoreData/CoreData.h> @interface MyTableViewController : UITableViewController { @protected NSFetchedResultsController *_fetchedResultsController; } And one more: #import <UIKit/UIKit.h> @interface MyChildTableViewController : MyTableViewController { } - (void)someMethod; The problem is that I can't use _fetchedResultsController in MyChildTableViewController class. I get compile-time error: '_fetchedResultsController' undeclared (first use in this function)` What's wrong here? kpower ughoavgfhw posted right answer in comments. I've asked

java - protected members accessed in derived class using base class instance

丶灬走出姿态 提交于 2019-12-03 10:03:21
问题 I created instance of base class in derived class and tried to access protected members. I can directly access protected members in a derived class without instantiating the base class. Base class: package com.core; public class MyCollection { protected Integer intg; } A derived class in the same package - package com.core; public class MyCollection3 extends MyCollection { public void test(){ MyCollection mc = new MyCollection(); mc.intg=1; // Works } } A derived class in a different package

How to simulate protected properties and methods in objective-c [duplicate]

落花浮王杯 提交于 2019-12-03 08:10:53
Possible Duplicate: Protected methods in objective-c The way to declare private properties is simple. You declare that in extension that's declared in .m files. Say I want to declare protected properties and access it from the class and subclass. This is what I tried: // // BGGoogleMap+protected.h // // #import "BGGoogleMap.h" @interface BGGoogleMap () @property (strong,nonatomic) NSString * protectedHello; @end That one is compile. Then I added: #import "BGGoogleMap+protected.h" @implementation BGGoogleMap () -(NSString *) protectedHello { return _ } @end Problem starts. I can't implement

How do I unit test a protected method in C++?

≡放荡痞女 提交于 2019-12-03 07:10:13
问题 How do I unit test a protected method in C++? In Java, I'd either create the test class in the same package as the class under test or create an anonymous subclass that exposes the method I need in my test class, but neither of those methods are available to me in C++. I am testing an unmanaged C++ class using NUnit. 回答1: Assuming you mean a protected method of a publicly-accessible class: In the test code, define a derived class of the class under test (either directly, or from one of its

Should protected attributes always be banned?

拥有回忆 提交于 2019-12-03 05:33:11
I seldom use inheritance, but when I do, I never use protected attributes because I think it breaks the encapsulation of the inherited classes. Do you use protected attributes ? what do you use them for ? In this interview on Design by Bill Venners, Joshua Bloch, the author of Effective Java says: Trusting Subclasses Bill Venners: Should I trust subclasses more intimately than non-subclasses? For example, do I make it easier for a subclass implementation to break me than I would for a non-subclass? In particular, how do you feel about protected data? Josh Bloch: To write something that is both

Testing private class member in C++ without friend [duplicate]

限于喜欢 提交于 2019-12-03 05:01:32
问题 This question already has answers here : How do I test a private function or a class that has private methods, fields or inner classes? (51 answers) Closed last year . Today I had a discussion with a colleague on whether to test or not to test private members or private state in the class. He almost convinced me why it makes sense. This question does not aim to duplicate already existing StackOverflow questions about the nature and reason of testing private members, like: What is wrong with

Workaround to accomplish protected properties in Objective-C

痴心易碎 提交于 2019-12-03 01:02:44
问题 I've been trying to find a workaround to declare @protected properties in Objective-C so only subclasses in the hierarchy can access them (read only, not write). I read that there is no documented way of doing this so I thought of this workaround and I wanted to ask StackOverflow's opinion about it. Every custom class at the top of the hierarchy contains three classes, one implementation and two interfaces. Let's name them: ClassA.h ClassA_protected.h ClassA.m Then any subclass of this ClassA

java - protected members accessed in derived class using base class instance

十年热恋 提交于 2019-12-03 00:36:55
I created instance of base class in derived class and tried to access protected members. I can directly access protected members in a derived class without instantiating the base class. Base class: package com.core; public class MyCollection { protected Integer intg; } A derived class in the same package - package com.core; public class MyCollection3 extends MyCollection { public void test(){ MyCollection mc = new MyCollection(); mc.intg=1; // Works } } A derived class in a different package - package secondary; import com.core.MyCollection; public class MyCollection2 extends MyCollection{

How do I unit test a protected method in C++?

喜欢而已 提交于 2019-12-02 20:43:27
How do I unit test a protected method in C++? In Java, I'd either create the test class in the same package as the class under test or create an anonymous subclass that exposes the method I need in my test class, but neither of those methods are available to me in C++. I am testing an unmanaged C++ class using NUnit. Assuming you mean a protected method of a publicly-accessible class: In the test code, define a derived class of the class under test (either directly, or from one of its derived classes). Add accessors for the protected members, or perform tests within your derived class .