access-modifiers

“protected” methods in C#?

狂风中的少年 提交于 2019-12-04 22:40:02
What are the benefits to defining methods as protected in C#? like : protected void KeyDemo_KeyPress( object sender, KeyPressEventArgs e ) { // some code } As compared to something like this: private void FormName_Click( object sender, EventArgs e ) { //some code } I've seen such examples in many books and I don't understand why and when do they use private vs protected ? Protected methods can be called from derived classes. Private methods can't. That's the one and only difference between private and protected methods. Often 'protected' is used when you want to have a child class override an

what's the difference between static, final and const members at compile time in Dart? [closed]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 21:10:17
Like the title suggests, what's the difference between static, final and const at compile time in Dart? When are they computed and when are memory allocated for each type? Can a heavy use of static variables lead to performance issues or OOM? static is to declar class level members (methods, fields, getters/setters). They are in the class' namespace. They can only be accessed from within the class (not subclasses) or with the class name as prefix. class Foo { static bar() => print('bar'); void baz() => bar(); // ok } class Qux extens Foo { void quux() => bar(); // error. There is no `bar()` on

Assigning Typescript constructor parameters

為{幸葍}努か 提交于 2019-12-04 20:51:40
问题 I have interface : export interface IFieldValue { name: string; value: string; } And I have class that implements it : class Person implements IFieldValue{ name: string; value: string; constructor (name: string, value: string) { this.name = name; this.value = value; } } after reading this post I've thinking about refactoring : class Person implements IFieldValue{ constructor(public name: string, public value: string) { } } Question : In first class I have fields which by default should be as

why python does not have access modifier?And what are there alternatives in python?

孤人 提交于 2019-12-04 18:10:41
问题 why python does not have Access modifier like in c#, java i.e public, private etc.what are the alternative way of encapsulation and information hiding in python. 回答1: From Wikipedia: [Python] has limited support for private variables using name mangling. See the "Classes" section of the tutorial for details. Many Python users don't feel the need for private variables, though. The slogan "We're all consenting adults here" is used to describe this attitude. Some consider information hiding to

Have you ever seen design with reasonable usage of protected internal access modifier?

只谈情不闲聊 提交于 2019-12-04 17:38:43
问题 I haven't, but I don't say there isn't one. All of the C# developers who read this probably do know what is protected internal and when to use it. My question is simple : did you actually ever use it or worked on a successfully designed project using protected internal access modifier? If yes, please share your knowledge and post nice sample, where I can finally appreciate clever usage of this tricky modifier. // I believe this isn't subjective, I am actually seeking for an answer ;-) 回答1: I

Java: Subclass access without package access

僤鯓⒐⒋嵵緔 提交于 2019-12-04 11:18:25
问题 Fairly new to Java, but I'm wondering why package access is considered "more restrictive" than subclass access. That is, every access modifier which provides subclasses with access to a member also provides the whole package with access, and there are modifiers whic provide package access but not subclass access. Isn't this totally backwards? Let's say I have a class ControlledInstantiation in some package. If I have another class AlsoControlledInstantiation extends ControlledInstantiation, I

What access modifier for testable helper methods?

馋奶兔 提交于 2019-12-04 11:08:36
In Java, helper methods are often marked protected instead of private , so that unit tests within the same package can test the helper methods. (Specifically, I am using JUnit.) This does not seem to work in Kotlin. What access modifier is recommended instead? internal (or no modifier) works well here 来源: https://stackoverflow.com/questions/30000983/what-access-modifier-for-testable-helper-methods

Inheritance breaking encapsulation?

流过昼夜 提交于 2019-12-04 08:01:27
People say inheritance breaks encapsulation, which i agree with. They say delegation is better- although the modifiers in delegation can also be public/protected. So is the real reason why inheritance breaks encapsulation because of the "knock-on" effect of the public/protected modifiers from the super class being exposed to any new classes which extend the current subclass? Yes. Since it gives the derived class access to members of the base class (depending on what language and which kind of inheritance) it is said that it breaks encapsulation. IMHO this is only if you are clinging to

Are private methods really safe?

人盡茶涼 提交于 2019-12-04 07:42:12
问题 In Java the private access modifier consider as safe since it is not visible outside of the class. Then outside world doesn't know about that method either. But I thought Java reflection can use to break this rule. Consider following case: public class ProtectedPrivacy{ private String getInfo(){ return "confidential"; } } Now from another class I am going to get Info: public class BreakPrivacy{ public static void main(String[] args) throws Exception { ProtectedPrivacy protectedPrivacy = new

C# - Internal Properties “readable” in quickwatch but not using reflection?

*爱你&永不变心* 提交于 2019-12-04 04:10:05
问题 I see that the "Quick Watch" window has access to all properties, irrespective of access restrictions (internal, protected, private) of a class in a library, even when the library is referenced in a totally different app,lib and namespace. Whereas I am not finding a way to access these using "reflection". I am especially trying to "read" (note - just read) the internal property of an assembly. If this is not possible by design of how "internal" works (not accessible outside the same namespace