nested-class

Where and how to use nested classes? [duplicate]

℡╲_俬逩灬. 提交于 2019-12-04 18:38:01
问题 This question already has answers here : Why/when should you use nested classes in .net? Or shouldn't you? (13 answers) Closed 6 years ago . I am thinking that if a class will be instantiated only in another class so it is right to use it nested in that class.I think this will help us good design.When i look at my project i have almost never seen such nested structure.But if i try to nested classes so this time another questions appear in my mind.For example I have Board class, Move classes

Visibility of nested class constructor

♀尐吖头ヾ 提交于 2019-12-04 17:48:16
问题 Is there a way to limit the instantiation of the nested class in C#? I want to prevent nested class being instantiated from any other class except the nesting class, but to allow full access to the nested class from other code. 回答1: Usually I create an interface for the functionality you want to expose to other classes, then make the nested class private and implement that interface. This way the nested class definition can stay hidden: public class Outer { private class Nested : IFace {

How to access nested static classes using Rjb?

故事扮演 提交于 2019-12-04 15:18:59
Lets say a Java program defines the class A, which has a nested static class 'B'. How is it possible to access class B using the Ruby-Java Bridge? For example, these attempts do not work: A = Rjb::import('package.A') A.B A::B Is there a way to accomplish this? Google cached this result from 2006. Sounds reasonable though, so take it and experiment! (PS: I'm a java + ruby user, but never used Rjb, so just passing along the info...) http://webcache.googleusercontent.com/search?q=cache:1p7OdptgsYUJ:blog.voneicken.com/2006/12/3/accessing-inner-java-classes-via-rjb+inner+class+rjb+ruby+java&cd=10

Why can't outer classes extend inner classes?

℡╲_俬逩灬. 提交于 2019-12-04 12:35:55
问题 Why can't I do this/is there a workaround to accomplish this: package myPackage; public class A { public class B { } } package myPackage; import myPackage.A.B; public class C extends B { } package myPackage; public class Main { public static void main(String[] args) { A myA = new A(); C myC = myA.new C(); } } The two compilation errors are On public class C extends B , No enclosing instance of type A is available due to some intermediate constructor invocation On C myC = myA.new C(); , A.C

Inheriting Nested classes into Subclass

时光怂恿深爱的人放手 提交于 2019-12-04 09:16:43
When I was going through this article, under the section Private Members in a Superclass , i saw this line A nested class has access to all the private members of its enclosing class—both fields and methods. Therefore, a public or protected nested class inherited by a subclass has indirect access to all of the private members of the superclass. My question is how can we DIRECTLY access the Nested class of Base in Derived (like we can access any public , protected fields)? and if there is a way, how can Derived access p which is private field of Base through Nested ? public class Base {

C#: Is a private inner interface possible?

左心房为你撑大大i 提交于 2019-12-04 06:45:24
I have a generic class X<T> ; This class has a covariant part that I want to be able to access covariantly. So I factor it out into an interface IX<out T> . However, I want this interface to be visible only to the class itself, because it contains also methods that are ment to be private . I.e., inside the class itself, I can upcast to IX<T> and use it covariantly. E.g.: class X<T> : IX<T> { private interface IX<out T>{ // the private covariant interface void foo(); } // It grants access to the private method `foo` private T foo(){...} public T IX.foo(){ return foo(); } private static void

Private nested static class - Good or bad practice?

六月ゝ 毕业季﹏ 提交于 2019-12-03 23:26:48
Would it be considered a bad practice to nest a private static class inside of a non-static class? public class Outer { private static class Inner { } } The idea here is that all instances of 'Outer' would share access to the static state. Another way to do it might be to just let the Inner class be non-static and use a static instance of it: public class Outer { private static innerInstance = new Inner(); private class Inner { } } Similar effect. What are the pros / cons or other considerations with this approach? I must admit that I almost never use nested classes, whether static or not, but

Inheritance + NestedClasses in C#

99封情书 提交于 2019-12-03 18:03:24
问题 We can have nested classes in C#. These nested classes can inherit the OuterClass as well. For ex: public class OuterClass { // code here public class NestedClass : OuterClass { // code here } } is completely acceptable. We can also achieve this without making NestedClass as nested class to OuterClass as below: public class OuterClass { // code here } public class NestedClass : OuterClass { // code here } I am wondering, what is the difference between above two scenarioes? What is achievable

How to specify nested custom view class?

廉价感情. 提交于 2019-12-03 15:37:49
问题 Available nested classes SuperView and NestedView. class SuperView : UIImageView { class NestedView : UIImageView { var text : String = "Nested View" } var text : String = "Super View" var nested : NestedView? } I would like to set for a UIImageView the property named "Custom Class Name" to value "NestedView" inside the inspector of the storyboard scene. But the Interface Builder couldn't find "NestedView" class. 回答1: At this time, I think that Interface Builder only recognizes the names of

Why can't outer classes extend inner classes?

北慕城南 提交于 2019-12-03 07:13:46
Why can't I do this/is there a workaround to accomplish this: package myPackage; public class A { public class B { } } package myPackage; import myPackage.A.B; public class C extends B { } package myPackage; public class Main { public static void main(String[] args) { A myA = new A(); C myC = myA.new C(); } } The two compilation errors are On public class C extends B , No enclosing instance of type A is available due to some intermediate constructor invocation On C myC = myA.new C(); , A.C cannot be resolved to a type Frankly, I think the conceptual idea is sound: I want to make a subclass of