access-specifier

When should we consider using private or protected?

流过昼夜 提交于 2020-01-01 08:43:25
问题 Just wondering, when should we actually must use private or protected for some methods in the model? Sometimes I can't not be bothered to group my methods in private nor protected . I just leave it as it is. But I know it must be a bad practice, otherwise these 2 groupings won't be created in programming. Thanks. 回答1: If you plan to call a method externally, record.method() , then "public" If it will be used only internally, self.method() , then "private" If you plan to use it internally, but

Difference between the default access specifier and protected access specifier in java

只谈情不闲聊 提交于 2019-12-29 13:13:06
问题 I was trying to learn java and when I went through access specifiers I had a doubt. What is the difference between the default one if none is specified and the protected access specifier in java? 回答1: The protected specifier allows access by all subclasses of the class in question, whatever package they reside in, as well as to other code in the same package. The default specifier allows access by other code in the same package, but not by code that is in subclasses residing in different

Difference between the default access specifier and protected access specifier in java

故事扮演 提交于 2019-12-29 13:12:14
问题 I was trying to learn java and when I went through access specifiers I had a doubt. What is the difference between the default one if none is specified and the protected access specifier in java? 回答1: The protected specifier allows access by all subclasses of the class in question, whatever package they reside in, as well as to other code in the same package. The default specifier allows access by other code in the same package, but not by code that is in subclasses residing in different

What is the difference between access specifiers and access modifiers?

拈花ヽ惹草 提交于 2019-12-29 02:54:46
问题 In Java, are access specifiers and access modifiers the same thing? 回答1: "access modifier" is the official term for private , protected and public used in the Java language specification. "access specifier" is used synonymously in the Java API doc, but this is the first time I've noticed that. It's probably better to stick with the JLS term. 回答2: Referring to the Sun Java Docs they both seem to be the same: Access Modifier Search for access specifier on this page. 回答3: The term Access

Make java methods visible to only specific classes

不想你离开。 提交于 2019-12-29 00:48:13
问题 I have a manager class that is responsible for managing Objects of a certain kind. To do so it needs to manipulate these Objects, but these Objects have no relation to the manager whatsoever, so design technically, they are in separate packages "project.managers" and "project.objects" . The important thing is that the Objects in question should only be manipulated by the managers and nowhere else, but need to be accessible by every other class in the project. As such I'd like to have the

Class-specific method visibility

╄→尐↘猪︶ㄣ 提交于 2019-12-24 05:33:05
问题 Is there some object oriented thing that you can call some methods from certain classes, but not all of them? Is there something like that which is similiar to protected ? Say you have a method void foo() and you want it to be available to the programmer in a few types of classes (perhaps something like using Type variables (to specify: T type ). Now, perhaps is there some way, without inheriting the class with foo() in it, or making an interface, to specify which classes or types of classes

Class-specific method visibility

人盡茶涼 提交于 2019-12-24 05:33:01
问题 Is there some object oriented thing that you can call some methods from certain classes, but not all of them? Is there something like that which is similiar to protected ? Say you have a method void foo() and you want it to be available to the programmer in a few types of classes (perhaps something like using Type variables (to specify: T type ). Now, perhaps is there some way, without inheriting the class with foo() in it, or making an interface, to specify which classes or types of classes

Is size of the object affected by type of access-specifier and type of inheritance?

萝らか妹 提交于 2019-12-23 07:26:23
问题 While answering one of the question, there was a discussion thread below my answer. Which suggests that depending on the access specifier (or may be the type of inheritance) private/protected/public the sizeof the class object may vary! I still don't understand from their brief discussion, how is that possible ? 回答1: Note new language for C++11 below In C++03 , there is language that makes this possible, 9.2 [class.mem]/12 (emphasis mine): Nonstatic data members of a (non-union) class

Access private member variable of the class using its object (instance)

无人久伴 提交于 2019-12-23 04:07:10
问题 Here is a VB.NET code snippet Public Class OOPDemo Private _strtString as String Public Function Func(obj as OOPDemo) as boolean obj._strString = "I can set value to private member using a object" End Function End Class I thought we cannot access the private members using the object, but perhaps CLR allows us to do that. So that means that access modifiers are based on the type and not on the instance of that type. I have also heard that c++ also allows that.. Any guesses what could be the

Is there a way to call a private Class method from an instance in Ruby?

青春壹個敷衍的年華 提交于 2019-12-22 01:44:56
问题 Other than self.class.send :method, args... , of course. I'd like to make a rather complex method available at both the class and instance level without duplicating the code. UPDATE: @Jonathan Branam: that was my assumption, but I wanted to make sure nobody else had found a way around. Visibility in Ruby is very different from that in Java. You're also quite right that private doesn't work on class methods, though this will declare a private class method: class Foo class <<self private def