encapsulation

C# “is inaccessible due to its protection level” error in constructor

Deadly 提交于 2019-12-23 09:17:38
问题 The constructor of the child class "caesar" gives an error. It says that name, type is inaccessible due to its protection level. How come? As this is a child class derived from "Cipher" class it shouldn't give an error like this. How can I overcome this situation. But I want those variables to be private. I don't want to change them as public. ***The second code example works. Can anybody see a difference? namespace Encrypter { class Cipher { public Cipher(string name, string type) { setName

How to design a returned stream that may use skip

假如想象 提交于 2019-12-23 04:13:16
问题 I have created a parsing library that accepts a provided input and returns a stream of Records. A program then calls this library and processes the results. In my case, my program is using something like recordStream.forEach(r -> insertIntoDB(r)); One of the types of input that can be provided to the parsing library is a flat file, which may have a header row. As such, the parsing library can be configured to skip a header row. If a header row is configured, it adds a skip(n) element to the

JavaScript Encapsulation with WebComponents/ShadowDOM

亡梦爱人 提交于 2019-12-22 08:16:53
问题 Probably simple question, that I haven't really found an answer for: Does ShadowDOM or WebComponents (as the bigger Standard) actually encapsulate JavaScript aswell? Like having seperate namespaces for each component? From what I encountered with Polymer that wasn't the case yet, which is obvious, given that polymer is doing it's polyfilling through JS. Thanks! 回答1: The Shadow DOM and Custom Element specs say nothing about script encapsulation. The only thing that SD gives you is <style>

Data Encapsulation in Perl?

左心房为你撑大大i 提交于 2019-12-22 04:06:18
问题 Hello Perl community on SO. I am using Perl since a few years, but since I am following SO, I recognized that I know Perl not enough. I wrote I quite big script over the past 4 years and tried to do this in OO style. I know that Perl<6 is not really OO. So one point I don't like is that I have no data encapsulation, that means no Variables that are really private to a package ("class") (or maybe I don't know how to do it). I have something like this (only a small part of my script) package

C++ private virtual inheritance problem

℡╲_俬逩灬. 提交于 2019-12-22 01:26:48
问题 In the following code, it seems class C does not have access to A's constructor, which is required because of the virtual inheritance. Yet, the code still compiles and runs. Why does it work? class A {}; class B: private virtual A {}; class C: public B {}; int main() { C c; return 0; } Moreover, if I remove the default constructor from A, e.g. class A { public: A(int) {} }; class B: private virtual A { public: B() : A(3) {} }; then class C: public B {}; would (unexpectedly) compile, but class

How do you do “true” encapsulation in C++?

删除回忆录丶 提交于 2019-12-21 23:34:48
问题 Encapsulation (information hiding) is a very useful concept, ensuring that only the barest minimal details are published in the API of a class. But I can't help thinking that the way C++ does this is a little deficient. Take, for example, a (Celsius-based) temperature class like: class tTemp { private: double temp; double tempF (double); public: tTemp (); ~tTemp (); setTemp (double); double getTemp (); double getTempF (); }; Now, that's a very simple case but it illustrates a point that the

C# Object reference not set to an instance of an object. Instantiating Class within a List?

。_饼干妹妹 提交于 2019-12-21 04:25:21
问题 public class OrderItem { public string ProductName { get; private set; } public decimal LatestPrice { get; private set; } public int Quantity { get; private set; } public decimal TotalOrder { get {return LatestPrice * Quantity;}} public OrderItem(string name, decimal price, int quantity) { } public OrderItem(string name, decimal price) : this(name, price, 1) { } } Above is the class, just for some background. public void AddProduct(string name, decimal price, int quantity) { lstOrderitem.Add

Whats the point of accessing private variables through getter and setter (accessor) functions?

被刻印的时光 ゝ 提交于 2019-12-21 03:55:34
问题 In classes, variables are often made private for encapsulation, and to limit the variables to a certain scope allow better error control and fewer bugs. This makes sense, as the fewer places a variable can be accessed the fewer places a bug can occur with that variable. However, I always see variables made private, and then a getter and setter function used to retrieve that value (sometimes even a pointer to that variable!). For example int a is private to prevent public access, but then getA

MVC 3, reuse of partial views and jquery, without conflicting the DOM

浪子不回头ぞ 提交于 2019-12-21 03:49:40
问题 As i am still new to MVC 3 and jquery, i would like to know a best practice solution to how the following can be solved: I have a view, where I use jquery ajax to fetch and display a partial view with some product details for product A. The loaded partial view consist of a bunch of html and jquery code, which is tied to the defined id's within the partial view. Thus, i would like to reuse the same partial view to show details from other products on the same View (e.g. show product B details

Do Subclasses Inherit Private Instance Variables From Superclasses

感情迁移 提交于 2019-12-21 00:53:46
问题 Do subclasses inherit private fields? This question addresses the same problem but I don't quite understand how that satisfies the (seemingly) contradictory situations below. http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html Says that "A subclass does not inherit the private members of its parent class." This means that it neither inherits private instance variables nor private methods right? However, how does this work if it inherits a public accessor method from its parent?