tags:

views:

57

answers:

1

Consider the following nested type:

 public class Book
 {

    private class Chapter
    {

    }

 }

As the chapter type is controlled by Book, is it a means of composition or is it a bad assumption to think composition here?

I am not sure, so to understand this I raised the question.

+5  A: 

No, it's not. You are just declaring a type that's scoped inside another one. If you also had it as a field of the enclosing type then it would have been considered composition like:

class Book
{
   private class Chapter
   {
   }

   private Chapter ChapterOne; // a field; actual usage of Chapter type
}

Note that it doesn't matter a bit that the Chapter class is a nested type or not. What matters is the usage of some type as a field inside another.

Mehrdad Afshari
Thanks Mehrdad for expln