public

Access Modifiers - what's the purpose?

旧巷老猫 提交于 2019-12-05 09:13:54
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! There are thousands of reasons, but I'll quote a few from here and then expand on those: Hiding the internals of the object protects its integrity by preventing users from

Besides accessibility, what else access-specifiers effects?

泪湿孤枕 提交于 2019-12-05 04:29:57
Besides the normal explenation of being visible or not to derived classes, is their any other difference? If you make it more visible, is it taking more or less memory, does it slow thing down or...? Nawaz Apart from the accessibility of members outside or to the derived classes, access specifiers might affect the object layout. Quoting from my other answer : Usually, memory address for data members increases in the order they're defined in the class . But this order may be disrupted at any place where the access-specifiers ( private , protected , public ) are encountered . This has been

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

寵の児 提交于 2019-12-05 01:34:01
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? 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 On My Machine (TM).) To create the template: Right-click in your project and choose Add > Class. You can

iOS: How to define public methods?

三世轮回 提交于 2019-12-04 19:54:14
问题 How can I define a method that can be called from anywhere, in every viewcontroller class? I have a method that brings me a json file, and i want it to be reusable, since i have several json calls on my app. Can you help me? 回答1: You can add it through a category: EDIT Create a new .h .m file pair and in the .h file: @interface UIViewController(JSON) -(void) bringJSON; -(void) fetchData:(NSData*) data; @ end Then in the .m file: @implementation UIViewController(JSON) -(void) bringJSON {

What is the difference between export and public in typescript?

 ̄綄美尐妖づ 提交于 2019-12-04 19:11:31
问题 I think this is a different slant on this question. And maybe the question is better phrased, when would you use public, as opposed to export? From my reading it seems like anywhere a C#/Java person thinks public, what you actually want is export. When/where would you use public instead of export? 回答1: public as a visibility modifier technically does nothing (all class members are public by default); it exists as an explicit counterpart to private . It's legal only inside classes. export does

returning reference to private vs public member

ⅰ亾dé卋堺 提交于 2019-12-04 16:05:59
I would like to know what could be reasons to provide a public access method returning a reference instead of making the member public. QPoint has methods int& rx and int& ry that let me directly manipulate the coordinates. I guess the implentation looks similar to this: public: int& rx(){return x;} private: int x; The only idea I had so far is the following: By keeping the member private and "only" providing a reference, the class can still change to use a different data type for its coordinates and while still "somehow" returning a reference to an int. However, this "somehow" would always

Public Static variable in excel vba

主宰稳场 提交于 2019-12-04 10:32:39
问题 Is it possible to have a static variable declared in one procedure, and use this variable in several different procedures using Excel VBA? i.e. Public myvar as integer Sub SetVar() static myvar as integer myvar=999 end sub sub Usevar() dim newvar as integer newvar=myvar*0.5 end sub I need myvar to be seen by other procedures, and not change or get "lost". The code above works if myvar is not declared as a static variable, but more code then the variable is "lost". If the static declaration is

Should class Square publicly inherit from class Rectangle?

谁说我不能喝 提交于 2019-12-04 10:15:41
I find this question very interesting after reading the part of "Effective C++" about public inheritance. Before it would be common sense for me to say yes, because every square is a rectangle, but not necessarily other way around. However consider this code: void makeBigger(Rectangle& r) { r.setWidth(r.width() + 10); } This code is perfectly fine for a Rectangle , but would break the Square object if we passed it to makeBigger - its sides would become unequal. So how can I deal with this? The book didn't provide an answer (yet?), but I'm thinking of a couple of ways of fixing this: Override

jQuery plugin creation and public facing methods

无人久伴 提交于 2019-12-04 09:59:10
I have created a plugin to convert an HTML select box into a custom drop down using DIV's. All works well, but i'd like to make it a little better. see my jsFiddle At the end of the plugin I have 2 methods, slideDownOptions & slideUpOptions, I would like to make these available outside of the plugin so other events can trigger the action. Im getting a little confused how to do this and more specifically how to call the methods from both within the plugin AND from outside of the plugin. Any help always appreciated Think about refactoring your plugin using object oriented code. With this you can

Override public method in subclass in a way that restricts public access while still allowing access from parent class?

蓝咒 提交于 2019-12-04 06:19:36
问题 I have a generic Collection class, with a variety of public getter methods. To get one item from the Collection, you call get(). There are also several methods that return multiple items: getMany(), getRange(), getAll(), find(), findAll(), query(), queryAny(), etc. Internally, all of these methods that return multiple items have a loop that calls get() repeatedly, as they aggregate the individual items to return. A simplified example: public function get($key){ return $this->collection[$key];