nested-class

Java: reusable encapsulation with interface, abstract class or inner classes?

I try to encapsulate. Exeption from interface, static inner class working, non-static inner class not working, cannot understand terminology: nested classes, inner classes, nested interfaces, interface-abstract-class -- sounds too Repetitive! BAD! --- Exception 'illegal type' from interface apparently because values being constants(?!) ...

Visibility of nester class constructor

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. ...

Java: limit to nest classes?

A very poor style to code but sometimes unavoidable. It is an extreme example. So is there some limit for nesting classes? are they equivalent? how do you deal with such situations? Create library? Code new FileObject().new Format().new Words().new Some().new Continue someThing; ((((new FileObject()).new Format()).new Words()).ne...

Static nested class visibility issue with Scala / Java interop

Suppose I have the following Java file in a library: package test; public abstract class AbstractFoo { protected static class FooHelper { public FooHelper() {} } } I would like to extend it from Scala: package test2 import test.AbstractFoo class Foo extends AbstractFoo { new AbstractFoo.FooHelper() } I get an error, "...

iPhone Setting ViewController nested in NSMutableArray

Hello I'm trying to set attributes for a viewcontroller nested inside a NSMutableArray, for example I have 3 ViewController inside this array: FirstViewController *firstViewController = [FirstViewController alloc]; SecondViewController *secondViewController = [SecondViewController alloc]; ThirdViewController *thirdViewController = [Thir...

Rails accepts_nested_attributes_for callbacks

I have two models Ticket and TicketComment, the TicketComment is a child of Ticket. ticket.rb class Ticket < ActiveRecord::Base has_many :ticket_comments, :dependent => :destroy, :order => 'created_at DESC' # allow the ticket comments to be created from within a ticket form accepts_nested_attributes_for :ticket_comments, :re...

class modifier issues in C# with "private" classes

I had a class that had lots of methods: public class MyClass { public bool checkConditions() { return checkCondition1() && checkCondition2() && checkCondition3(); } ...conditions methods public void DoProcess() { FirstPartOfProcess(); SecondPartOfProcess(); Thir...

Rails 3 ActiveModel Nested Class I18n

Given the following class definition in ruby: class Conversation class Message include ActiveModel::Validations attr_accessor :quantity validates :quantity, :presence => true end end How can you use i18n to customize to error message. For example the correct lookup for the class Conversation would be activemodel: er...

C++ non-member functions for nested template classes

I have been writing several class templates that contain nested iterator classes, for which an equality comparison is required. As I believe is fairly typical, the comparison is performed with a non-member (and non-friend) operator== function. In doing so, my compiler (I'm using Mingw32 GCC 4.4 with flags -O3 -g -Wall) fails to find the ...

Static member class - declare class private and class member package-private?

Consider you have the following class public class OuterClass { ... private static class InnerClass { int foo; int bar; } } I think I've read somewhere (but not the official Java Tutorial) that if I would declare the static member classes attributes private, the compiler had to generate some sort of acce...

Using nested classes for constants?

What's wrong with using nested classes to group constants? Like so: public static class Constants { public static class CategoryA { public const string ValueX = "CatA_X"; public const string ValueY = "CatA_Y"; } public static class CategoryB { public const string ValueX = "CatB_X"; pu...

Nested Class member function can't access function of enclosing class. Why?

Please see the example code below: class A { private: class B { public: foobar(); }; public: foo(); bar(); }; Within class A & B implementation: A::foo() { //do something } A::bar() { //some code foo(); //more code } A::B::foobar() { //some code foo(); //<<compiler doesn't lik...

Where and how to use nested classes ?

Hello everybody 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 ...

Strange enable_if behaviour using nested classes (MSVC compiler bug or feature?)

After quite some time debugging my code, I tracked down the reason for my problems to some unexpected template specialization results using enable_if: The following code fails the assertion in DoTest() in Visual Studio 2010 (and 2008), while it doesn't in g++ 3.4.5. However, when i remove the template from SomeClass or move *my_conditio...

NHibernate query against nested class

I'm using NHibernate. I have a class which has a nested type. Is there any way, using NHibernate, to query against the nested type, asides from using a native SQL query? Nested classes are not allowed in HQL currently. EDIT: The outer class has an IList of nested class instances. ...

Template friend and nested classes

Hello, please consider the following code: template <typename T> struct foo { template <typename S> struct bar { template <typename> friend struct bar; }; }; I'd like all instantiations of foo<T>::bar to be friends of foo<T>::bar<S> for any S. If bar is not a nested template, the syntax above works just fine. B...

What are reasons why one would want to use nested classes?

In this stackoverflow answer a commenter mentioned that "private nested classes" can be quite useful so I was reading about them in articles such as this one which tend to explain how nested classes function technically, but not why you would use them. I suppose I would use private nested classes for little helper classes that belong to...

Why do I get an error trying to refer a nested class in Ruby?

Why there is an error in the following example? class ClassA class ClassB end class ClassC def test ClassB.new end end end p ClassA::ClassC.new.test # => #<ClassA::ClassB:0x0000010103f860> class ClassA class ClassD def test ClassB.new end end end p ClassA::ClassD.new.test # => #<ClassA::ClassB:...

(Python) Closure created when it wasn't expected

I got an unexpected closure when creating a nested class. I suspect that this is something related to metaclasses, super, or both. It is definitely related to how closures get created. I am using python2.7. Here are five simplified examples that demonstrate the same problem that I am seeing (they all build off the first): EXAMPLE ...

Is it a good idea to have a class nested inside an interface?

Is it possible to have an inner class inside the interface in java ??? ...