nested-class

Why can't a class extend its own nested class in C#?

For example: public class A : A.B { public class B { } } Which generates this error from the compiler: Circular base class dependency involving 'A' and 'A.B' I always figured a nested class behaved just like a regular class except with special rules concerning accessing the outer class's private members, but I guess there'...

"Public" nested classes or not

Suppose I have a class 'Application'. In order to be initialised it takes certain settings in the constructor. Let's also assume that the number of settings is so many that it's compelling to place them in a class of their own. Compare the following two implementations of this scenario. Implementation 1: class Application { Applic...

How do I override methods of nested types?

I've got a custom TObjectList descendant in Delphi 2009, and I'd like to play with its enumerator a bit and add some filtering functionality to the MoveNext method, to cause it to skip certain objects. MoveNext is called by DoMoveNext, which is a virtual method, so this shouldn't be difficult to override... except for one thing. The TEn...

.NET Nested Classes

The current class library I am working on will have a base class (Field) with over 50 specific "field" types which will inherit from "Field" and nested for maintain readability. For example... abstract class Field { public int Length { get; set; } public class FieldA : Field { public static void DoSomething() ...

Return a nested class type in Java

I have a base class that has an abstract getType() method. I want subclasses to be able to implement this method and provide the actual class to use. In code, something like the following: public abstract class A { public static interface Tile; protected abstract Class<Tile> getTileClass(); } public class B extends A { p...

Remove nested test classes with maven2

Hi There! I use nested classes for accessing private members in JUnit tests. They are alaways named "TestProxy". I would like to remove them at Build time using maven2, to not include it into the jar file. -Is there any configuration option? -Can it be done with a plugin? If so, a prototype would be nice! ;-) Thanks Edit: Why us...

C#: Extension methods not allowed in nested static classes?

Why is this? I would find it really nice to be able to have some extension methods locked down to be used only within one of my classes. Don't really want to have certain extension methods available everywhere... and they look so much nicer than regular static methods :P For clarification: The reason I want these extension methods is...

Eclipse warning about synthetic accessor for private static nested classes in Java?!

My coworker suggested making several of the Eclipse code-formatting and warning settings to be more rigorous. The majority of these changes make sense, but I get this one weird warning in Java. Here's some test code to reproduce the "problem": package com.example.bugs; public class WeirdInnerClassJavaWarning { private static class ...

Inner classes in C#

Until very recently I hadnt twigged that there was a difference between a normal class, and an inner class / sub class. What is the relationship between an instance of an inner class and an instance of its containing class, and what is the purpose of inner classes / what makes them different? ...

nested struct with array

Please, help me to create a nested struct with an array. How do I fix this code? class CMain { public: CMain(); ~CMain(); private: struct { CCheckSum() : BufferSize(500) {memset(Buffer, 0, BufferSize);} const int BufferSize; char Buffer[BufferSize]; }Sm...

C# Nested typed lists

I've created a class witch contains a typed list and derives to another class I created. This looks as follows: namespace MyIntegretyCheck.Common { /// <summary> /// Description of PolicyErrors. /// </summary> public partial class PolicyErrorEndingDates { public int ID_P {get;set;} public DateTime DT_S_E {g...

Refactoring: Nested class or separate classes?

Hi, I'm currently doing some refactoring (+ adding new features) to some of our framework classes. The situation is that we have a single (god-like) class which does a bunch of logic we'd like to split up. The class represents something like a validation rule for fiscal codes. So it does validation of the names of the person, birthdate ...

How does the .net framework nest forms in classes. (vb.net).

If I look at some classes in the framework, using reflector, I can see that forms and user controls are made private and nested into a parent class. For instance, I have a control which makes use of pop-up form that is specific to that control. At the moment, I make the pop-up form friend accessible. If I wanted to do it the framework w...

When would you want to nest classes in C#?

Specifically, can anyone give me concrete examples of when or when not to use nested classes? I've known about this feature since forever, but never had a reason to use it. Thanks. ...

Nested Classes w/ Same Name in Separate Assemblies Causing Serialization Headaches

I’m working with a poorly-engineered API. I have a class that I need to serialize, and I have control over the makeup of the class, but not the types that make up the properties the class is serialzing. An example is below: <Project> <SomeProperty1 /> <Install> <DefaultStep></DefaultStep> </Install> <Uninstall> <DefaultS...

Can a nested C++ class inherit its enclosing class?

I’m trying to do the following: class Animal { class Bear : public Animal { // … }; class Giraffe : public Animal { // … }; }; … but my compiler appears to choke on this. Is this legal C++, and if not, is there a better way to accomplish the same thing? Essentially, I want to create a cleaner...

Why is my nest class being seen as abstract?

I have an abstract base class which contains a private nested implementation. visual c++ is giving me the following error when I try to instantiate the non-abstract nested implementation: error C2259: 'node::empty_node' : cannot instantiate abstract class (line 32) as far as I can tell, I've overridden all the abstract members of the ...

When should I use/examples of nested classes?

Please retag this question to include languages to which it is relevant So my java book had a whole chapter on nested classes, but ended on the note that you should only really use them when it comes to "modeling composition relationships and implementing internals of a class you want to hide". So lets discuss when you would want to use...

Where do you put collection classes?

I am not sure if there is already a nomenclature for this, but for the sake of this question lets define two terms: peer implementation or nested implementation to illustrate how you implement collection classes in a data model that contains many parent/child entity relationships. I use the term peer to describe the scenario where you i...

How to restrict access to nested class member to enclosing class ?

Hi, Is it possible to specify that members of a nested class can be accessed by the enclosing class, but not other classes ? Here's an illustration of the problem (of course my actual code is a bit more complex...) : public class Journal { public class JournalEntry { public JournalEntry(object value) { ...