protected

C++: Is there a way to limit access to certain methods to certain classes without exposing other private members?

I have a class with a protected method Zig::punt() and I only want it to be accessible to the class "Avocado". In C++, you'll normally do this using the "friend Avocado" specifier, but this will cause all of the other variables to become accessible to "Avocado" class; I don't want this because this breaks encapsulation. Is what I want i...

Object Class's protected method MemberWiseClone()

This might be a dumb question, but I don't get it: I have a class called Card. I want to do a shallow clone using MemberWiseClone(). In Theory Card inherits from Object. So it should be able to use MemberWiseClone(), even if MWC() is protected ?? Am I missing/forgetting something? ...

Test-driven Development: Writing tests for private / protected variables

I'm learning TDD, and I have a question about private / protected variables. My question is: If a function I want to test is operating on a private variable, how should I test it? Here is the example I'm working with: I have a class called Table that contains an instance variable called internalRepresentation that is a 2D array. I want...

Why can't my subclass access a protected variable of its superclass, when it's in a different package?

I have an abstract class, relation in package database.relation and a subclass of it, Join, in package database.operations. relation has a protected member named mStructure. In Join: public Join(final Relation relLeft, final Relation relRight) { super(); mRelLeft = relLeft; mRelRight = relRight; mStruct...

VB.NET Visual Inheritance: Friend VS Protected

Why is it that some components/controls will not be inherited visually in a child form if they are declared with the access modifier Friend vs when they are declared with Protected. For example, I've got a DataSet object in my Parent Form that was initially "Friend" (I drag and dropped it to the form, so it was shown as a control in th...

Any performance reason to put attributes protected/private ?

I "learned" C++ at school, but there are several things I don't know, like where or what a compiler can optimize, seems I already know that inline and const can boost a little... If performance is an important thing (gaming programming for example), does putting class attributes not public (private or protected) allow the compiler to ma...

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

Hello All, I must admit that I have been a manual tester and have just begun swimming through java (for selenium tool) I got to know that protected members of a class would be accessible in derived class. Despite this I created instance of base class in derived class and tried to access protected members (I agree that it sounds foolish...

Publishing protected videos online.. how to???

Dear All, as many of us is aware is possible to dowload youtube videos using AnyVideo converter or any similar software. The basic mechanism is that, when bufering a video, a set of images is sent to the client machine, that's because youtube videos are in flash format. Not sure which format, .f4v, 4fp . I assume is .f4v rather than .4f...

Protected Internal properties vs Protected properties and Resharper

I've just picked up Resharper and have been playing around converting fields to properties. I want these properties to be protected, but Resharper doesn't want to give me that option. Instead there is only a Protected Internal option. This has me thinking. Either there is a rule somewhere that properties should always be 'protected inter...

C++: Why does my DerivedClass's constructor not have access to the BaseClass's protected field?

I have a constructor attempting to initialize a field in a base class. The compiler complains. The field is protected, so derived classes should have access. //The base class: class BaseClass { public: BaseClass(std::string); BaseClass(const BaseClass& orig); virtual ~BaseClass(); const std::string GetData() const; ...

Parent's Enum in Java

In the code example below, I'm trying to test the value of an enum in the parent class. The error I get is "p.theEnum cannot be resolved or is not a field.", but it's the exact same code I use in the parent class to test the value (without the p. obviously). Where am I going wrong? :) public class theParent { protected static enum ...

Accessing a protected member variable outside a class

I'm querying for the ID of a field by accessing a class function which someone has already put in place. The result is a object returned with protected member variables. I'm struggling to see how I can access the member variable values outside the class. ...

PHP Accessing a child's private properties in parent

Hi I have a parent object that I use for general CRUD in my applications - it has basic save & retrieve methods so I can don't have to reinclude them them in all my objects. Most of my child objects extend this base object. This has worked fine, but I'm finding a problem with retrieving a serialized child object. I use a "retrieve" meth...

C++ "Variable not declared in this scope" - again

I guess this is a really simple question and, probably, one that has been answered several times over. However, I really do suck at C++ and have searched to no avail for a solution. I would really appreciate the help. Basically: #ifndef ANIMAL_H #define ANIMAL_H class Animal { public: void execute(); void setName(char*); Anima...

protected data in abstract class

My question involves specifically Java, abstract classes, and the use of protected data. I am being told that all the data should be private, and protected getters/setters used only. Now, I understand we want to shield data from direct manipulation by casual users of the class, and that public data members in general are a questionable...

Java : protected access across package

Hi, I was curious to understand what's happening here.( a protected member being accessed outside the package through a subclass ) I know for classes outside the package, the subclass can see the protected member only through inheritance. consider two packages - package1 and package2. 1) package1 - ProtectedClass.java pac...

Using make_shared with a protected constructor + abstract interface.

Given an abstract interface and an implementation derived from that interface, where constructors are protected (creation of these objects only being available from a class factory - to implement a DI pattern), how can I make use of make_shared in the factory function? For example: class IInterface { public: virtual void Me...

Base class defines many protected methods: Is it a good OOP design?

I wrote a base class which defined many protected methods. Those methods are called in its sub classes. The methods define basic operations for its sub classes. For instance: class Base{ protected void foo(){} protected void bar(){} } class Sub1 extends Base{//The sub class only needs Base.foo() public void po(){ ... ...

Moq modify protected on calling void method

I want to use moq a void method and set a value to a protected property when is called. public class MyClass{ public Guid Id {get; protected set; } } public interface IMyRespository { public void Save(MyClass myClass); } Something like: var moq = new Mock<IMyRespository>(); var my = new MyClass(); moq.Setup(x=>x.Save(my)); I want...

Protected Keyword C#

I want to know what is the meaning of protected in C#, why we use it, and the benefit of the keyword? For instance protected int currentColorIndex; Please elaborate. ...