private

subclass needs access to private attribute of abstract superclass

一笑奈何 提交于 2019-12-08 02:29:48
问题 I have an abstract java class that implements a couple of its methods, but not others. In the methods it implements it uses a private attribute variable. The variable used also needs to be used in a subclass. As I see it my options are: Declare the private variable in both the subclass and the super class defer the implementation of the methods currently implemented in the abstract class to the subclasses Are there other options? Which of these makes more sense and why? 回答1: The question is

JavaScript, call private function as a string inside public method without using eval (Revealing pattern)

大城市里の小女人 提交于 2019-12-07 15:44:30
问题 I'm trying to call a private function inside the revealing pattern. This is my code: var module = (function(){ var privateMethod = function(val) { console.log(val); } var publicMethod = function() { var functionString = "privateMethod"; /** This what I tried functionString.call('test'); window[module.privateMethod]('test'); */ } return { init: publicMethod } })(); $(document).ready(function(){ module.init(); }); Someone could help me? Thanks! 回答1: Make your private functions properties of an

How do I write module private/protected methods in python?

蓝咒 提交于 2019-12-07 11:27:21
问题 I understand that to write python module private/protected functions you use def _func(): ... but I have an object hierarchy with specialized overrides. Also I want to hide the internal implementation(since its not meant for outside use, and so I can hopefully improve it without breaking code, not that I think anybody will use it except me). If I use class Paragraph(Tag): def _method(self): ... and try calling _method from a different class that subclasses Tag IntelliJ IDEA(and probably

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

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

Besides accessibility, what else access-specifiers effects?

烈酒焚心 提交于 2019-12-07 01:32:37
问题 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...? 回答1: 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

Docker - Unable to push image to private registry

只谈情不闲聊 提交于 2019-12-06 19:00:59
问题 I have created my own private registry on my server by pulling and running the registry image. sudo docker run -d -p 5000:5000 registry After which, I tried to tag a simple image and push it to the server. sudo docker tag ubuntu:latest localhost:5000/myprivateubuntu And I received this error: Error: Invalid registry endpoint ... Get ... If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add '--insecure-registry localhost:5000' to the daemon's arguments

Access package private method in Scala REPL

大城市里の小女人 提交于 2019-12-06 18:59:27
Suppose I have a private[stuff] method Stuff.something in org.my.stuff . Is there something that I can do in the Scala REPL so that I can call Stuff.something without getting the error error: value something is not a member of org.my.stuff.Stuff ? In particular, can I get the REPL to be "inside" a given package (here org.my.stuff ), giving access to its private members? Rich Using "packages" in the REPL You cannot get a REPL prompt "inside" a given package, see https://stackoverflow.com/a/2632303/8261 You can use "package" statements inside " :paste -raw " mode in the REPL (see e.g. http:/

private template functions

寵の児 提交于 2019-12-06 17:08:05
问题 I have a class: C.h class C { private: template<int i> void Func(); // a lot of other functions }; C.cpp // a lot of other functions template<int i> void C::Func() { // the implementation } // a lot of other functions I know, that it's not the best idea to move template implementation in cpp file (because it won't be seen from other cpp's, which could include the header with the template declaration). But what about private functions? Could anyone tell me if there are cons of implementing of

subclass needs access to private attribute of abstract superclass

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 09:51:36
I have an abstract java class that implements a couple of its methods, but not others. In the methods it implements it uses a private attribute variable. The variable used also needs to be used in a subclass. As I see it my options are: Declare the private variable in both the subclass and the super class defer the implementation of the methods currently implemented in the abstract class to the subclasses Are there other options? Which of these makes more sense and why? The question is how you want to maintain your state: If it is of no concern, where the value is stored, you can just add a