access-modifiers

Call a protected method from outside a class in PHP

I have a very special case in which I need to call a protected method from outside a class. I am very conscious about what I do programmingwise, but I would not be entirely opposed to doing so in this one special case I have. In all other cases, I need to continue disallowing access to the internal method, and so I would like to keep the...

C#: Explicitly specifying the interface in an implementation's method

Why is it that when implementing an interface, if I make the method public I do not have to explicitly specify the interface, but if I make it private I have to...like such (GetQueryString is a method from IBar): public class Foo : IBar { //This doesn't compile string GetQueryString() { ///... } //But this ...

Protected Classes in .NET

Can a class be protected in.NET? Why is / isn't this possible? ...

What are public, private and protected in object oriented programming?

What are public, private and protected in object oriented programming? ...

Is there a way to make a value accessible only to the parent of a nested class VB.NET?

In general, according to the OOP paradigm, my understanding of encapsulation basically says: If a member is private, it can only be accessed by the class. If a member is protected, it can only be accessed by the base class and any derived classes. If a member is public, it can be accessed by anyone. If I have a nested class, can I de...

Why is internal protected not more restrictive than internal?

I'd like to create an internal auto-property: internal bool IP { get; protected internal set; } I thought it would be possible to make the setter protected or protected internal - but I always get the error accessibility modifier must be more restrictive than the property. Isn't that the case? Private does not help me, here. EDIT: Th...

Access modifiers on interface members in C#

I am getting a compile error from the following property. The error is: "The modifier 'public' is not valid for this item" public System.Collections.Specialized.StringDictionary IWorkItemControl.Properties { get { return properties; } set { properties = value; } } but if I remove the IWorkItemControl it compiles fine. W...

Proper application of access modifiers

I'm a student looking for resources which can help me further understand how to properly apply access modifiers to members/types as I code them. I know (in C#) what restrictions access modifiers like private, public, protected, etc. put into place. When I code my own little projects I have a tendency to just make everything public. I'm ...

Change the Access Modifiers of ASP.NET controls

If I put a control in a .aspx file like this; <asp:TextBox ID="protectedTextBox" runat="server">Some info</asp:TextBox> I get a declared control in the page's .aspx.designer.cs file; protected global::System.Web.UI.WebControls.TextBox protectedTextBox; But I'd like to change the access modifier of the control to public. Is there an...

Access modifier best practice in C# vs Java

Hi All, I understand that the rule of thumb in OOD is to minimize access to all members of a given object as best as can be reasonably accomplished. C# and Java both seem to implement the same set of access modifiers; however, something which has bewildered me for some time now is why Java classes seem to be mostly declared as public w...

What is the equivalent of Java's final in C#?

What is the equivalent of Java's final in C#? EDIT: Sorry, I should have been clearer. I meant what is the equivalent when applied to a member variable - so it must be assigned once and only once. ...

What is the equivalent of Java's default (package) access in C#?

What is the equivalent of Java's default (package) access in C#? Is there one? Is there anyway to restrict access to a particular namespace? The Problem: I'm trying to restrict access to certain methods to just my NUnit tests - in JUnit I would do this by making the methods package access and having the test in the same package but un...

java access modifiers

which access modifiers which when used with the method makes it available to all the class and subclasses within a package?? ...

C# Access Modifiers with Inheritance

I'd like to have multiple versions of an object with different access modifiers on the properties For example I might have a user class- public abstract class UserInfo { internal UserInfo() { } public virtual int ID { get; set; } public virtual string Password { internal get; set; } public virtual string Usernam...

Difference between "strict private" and "protected" Access Modifiers in Delphi?

Hi i'm a really noob, but i learn programming and after structured programming with Pascal language, i'm beginning to learn about OOP with Delphi. So, i don't really understand the difference between the 'strict private' instruction and the 'protected' one.. So here is my code, it's about a "bag" creation, it's just the introduction of ...

Signature Files and Acces Modifers in F#

I've recently been trying to learn the Object-Oriented aspects of F#, and have become curious about how to restrict access to types/modules in the language. More specifically, I want to know the difference between writing this: Example.fsi module Stack = val foo : string Example.fs module Stack = let foo = "foo" let bar...

StructureMap 2.5 and internal implementors.

Hi, is it possible to get this stuff working(some way to force Objectfactory create instances like Activator) in the below example everything is placed in a sigle assembly public interface IUnitOfWorkFactory { IUnitOfWork Create(); } internal class NHUnitOfWorkFactory : IUnitOfWorkFactory { public IUnitOfWork Create() { ...

Is there a reason you can not define the access modifier on a method or in an interface?

The responsibility of the visibility of a method is relegated to the class that implements the interface. public interface IMyInterface { bool GetMyInfo(string request); } In C# set access modifier public, private or protected before the method GetMyInfo() generates the following error: The modifier 'private' is not valid for this i...

How can I convince Visual Studio to not omit access modifiers when generating code?

Very often when Visual Studio generates code (for example generating an event handler stub) it omits access modifiers for members. I would like it to stop doing this. Is there a setting for this? ...

Why use public variables?

Variables, methods and classes can receive various security levels. From my C# experience, there is: public internal protected protected internal private Now, I understand the use of making methods and classes private, or internal or protected, but what about variables? Even if I make a variable private, I can use a Property to call it...