private

What's the best way to expose Java components such as a JButton in an MVC architecture?

非 Y 不嫁゛ 提交于 2019-12-05 19:30:58
I'm currently programming a Blackjack application in Java and it needs to be written in an MVC architecture. I have all my models, views and controllers fully coded and everything works perfectly. However, I'm wondering what the best way of attaching listeners to components is (e.g, a JButton). My current design declares all components in the view that need listeners as public final. It then passes the view to the controller. From there, the controller has full reign to access the components and add action listeners. Code example: public class View extends JFrame { public final JButton myBtn1

How do I mark a control as 'Private' in WPF?

穿精又带淫゛_ 提交于 2019-12-05 14:26:42
With WinForms programs I've become accustomed to marking the Modifiers property of a control as 'Private' to prevent external classes and whatever else have you from being able to see and mess with them. Being still very green with WPF, I see no obvious equivalent in WPF that allows me to make it so external classes cannot see a control I drop onto a form or another user control or what not. I did notice something of x:FieldModifier = "Private" but I get the error "x:FieldModifier = "Private" is not valid for the language C#". How do I mark a control as Private so it cannot be viewed or

Can a friend class object access base class private members on a derived class object?

无人久伴 提交于 2019-12-05 14:21:10
问题 I'm surprised that the code below compiles. It seems that a class befriended to the (publicly inherited) base class can access a member of the base class provided an instance of the derived class. If the inheritance is changed to private then compilation fails. In short, how is d.b_var valid within F::func(D& d) ? #include <iostream> #include <string> using namespace std; class B{ int b_var; friend class F; }; class D: public B{ int d_var; }; class F{ public: void func(D &d){ d.b_var = 5; } }

C++ private modifier ignored on nested anonymous struct

孤人 提交于 2019-12-05 14:17:42
问题 The following sample code compiles just fine in Visual C++: class Test { private: struct { struct { int privateData; }; }; }; int main(int, char **) { Test test; test.privateData = 0; return 0; } But why? I'd expect a compiler error because the privateData member should be inaccessible to the function main, since it's supposed to be private like its container's container. I know that nameless structs are not part of official C++, but this design is asinine. By the way I've also tried to

Private 'set' in C# - having trouble wrapping my brain around it

折月煮酒 提交于 2019-12-05 12:51:53
问题 I've seen a lot of example code written using something like (please forgive how horribly canned this is): public class Test { public object Thingy { get; private set; } } Unfortunately, these kinds of examples never really explain why 'set' is set as private. So, I'm just wondering if there's a good, common example that will illustrate to me why something like this would be used. I sort of see it - the property can be run to process some extra logic in addition to setting that field. I'm

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

邮差的信 提交于 2019-12-05 12:36:41
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 pylint/other checkers would also) give me a warning. Is there any way to fix this? My use case is a set of

Automatically change public to private (Java)

为君一笑 提交于 2019-12-05 10:23:41
I am doing a refactoring on code is translated from other languages into Java and I want to do it automatically. My problem is that I have a lot of methods that aren't private but are just called in the same class that they are declared and I want to make them private. I have a lot of classes and I guess if there is something that can help me to do it semi-automatically I would like to know it. Do you know if I can look for these methods to make them private fastly? I am using Eclipse. Replace all is one option. But I suggest you don't do it. private and public are there for the programmer. If

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

“Private” attribute properties in Python

别来无恙 提交于 2019-12-05 06:47:28
I'm relatively new to Python so I hope I haven't missed something, but here goes... I'm trying to write a Python module, and I'd like to create a class with a "private" attribute that can (or maybe 'should') only be modified through one or more functions within the module. This is in an effort to make the module more robust, since setting of this attribute outside of these functions could lead to unwanted behaviour. For example, I might have: A class that stores x and y values for a scatter plot, Data A function to read x and y values from a file and store them in the class, read() A function

Private class unit tests

爱⌒轻易说出口 提交于 2019-12-05 05:19:05
How to unit test private (means with package visibility) classed in java? I have a package, only one class is public in this package, other classes are private. How to cover other classed with unit tests? I would like to include unit tests in resting jar. Kowser Create the unit test class in the same package. For example, If com.example.MyPrivateClass located in src/main/java/com/example/MyPrivateClass.java Then the test class will be in same package com.example.MyPrivateClassTestCase and will be located in src/test/java/com/example/MyPrivateClassTestCase.java As indicated in @Kowser's answer,