access-modifiers

The size of a Get method

故事扮演 提交于 2019-12-08 15:41:10
问题 Are there any guidelines or general consensus towards the size of a 'Get' in terms of lines of code? I have a Get method on a member that has quite easily grown to 30 lines of code here. I'm not sure at what point this should be pulled out into a method. But then I'd only be calling it something like GetMyString and assigning the value to another member and calling it in the constructor anyway. Is it ever worth doing this? Is this too subjective for SO? 回答1: dcastro's answer is good but could

How to change the access modifier of a user control

丶灬走出姿态 提交于 2019-12-08 14:45:52
问题 I have a user control created in xaml, lets name it "View". In the View.xaml.cs I changed the access modifier for the class View to internal: internal partial class View : ViewBase { ... } After changing the access modifier the compiler states the error: Partial declarations of 'A.B.View' have conflicting accessibility modifiers My first guess was that the view has to be made internal via the xaml code. So I added two lines of xaml: x:Name="View" x:FieldModifier="internal" But this did not

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

帅比萌擦擦* 提交于 2019-12-08 02:25:51
问题 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 declare a property to be accessible only to that class and the parent class it's nested within? For example: Public Class ContainerClass Public Class NestedClass

Confusion on when to use private vs protected fields

牧云@^-^@ 提交于 2019-12-07 07:35:12
问题 I have seen users in SO saying that protected fields are bad, because it can introduce problems as the code grows. Please refer to the following code. public class Car { private String modelName; private int yearReleased; //getters and setters } If the Car class is extended by a class named ToyotaCar public class ToyotaCar extends Car{ // Toyota specific stuff } I want my ToyotaCar object to have a modelName and yearReleased fields. And that is why I decided to extend from Car class. But

Is there a tool in eclipse, a plugin for eclipse, or an external program that can automatically limit access modifiers?

人盡茶涼 提交于 2019-12-07 06:00:52
问题 I used to be incredibly bad at limiting access of my variables/methods/classes , I tended to use public a hell of a lot when I shouldn't. I was just wondering if there was any tool - plugin, external or otherwise - that can search your source code, find what calls your variables/methods/classes and changes the visibility if it's too high. So for example, if I had a public variable and nothing outside that class called it, then the tool would reduce its access to private. Mainly I need this

Access Modifiers - what's the purpose?

廉价感情. 提交于 2019-12-07 05:00:47
问题 I'm relatively new to programming in general and I was wondering if anyone could help me understand the purpose of access modifiers? I understand the fact that they set different levels of access for classes and variables etc. but why would you want to limit what has access to these? What is the point in not allowing access for different things? why not just allow access for everything? Sorry if this is a stupid question! 回答1: There are thousands of reasons, but I'll quote a few from here and

How come internal members in my view model aren't accessible in the view?

我的未来我决定 提交于 2019-12-07 03:09:47
问题 I have some internal automatic properties in my view model but my strongly-typed view doesn't see them. Everything is in the same assembly, so why is this happening? public class MyViewModel { public int PublicProperty { get; set; } internal int InternalProperty { get; set; } } . @*My view*@ @model MyViewModel @Model.PublicProperty @Model.InternalProperty @*Causes compilation error*@ 回答1: Views are compiled in a separate dynamically generated assembly by the ASP.NET runtime. So you cannot use

Visual C# 2010 Express: Specify default access modifier for new classes?

陌路散爱 提交于 2019-12-06 22:11:27
问题 Whenever I create new classes using Visual Studio 2010 Express C# it creates them with no access modifier. 9 times out of 10 I want my new classes to be public. How can I have Visual Studio create empty class templates with the "public" modifier by default? 回答1: The trick is to create a new item template named Class. Then when you do Add > New Class, your template will be selected by default rather than the built-in Class template. (I am not sure if this behaviour is guaranteed but it Works

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

霸气de小男生 提交于 2019-12-06 16:15:06
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 11 months ago . 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? 回答1: static is to declar class level

What access modifier for testable helper methods?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 06:42:15
问题 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? 回答1: internal (or no modifier) works well here 来源: https://stackoverflow.com/questions/30000983/what-access-modifier-for-testable-helper-methods