Christos
Christos

Reputation: 53958

many classes inside a class

The language I use is C#.

I have a problem of architectural nature. Let Class A has the following form:

Class A
{
    Class B
    {
        // properties goes here.
    }

    Class C
    {
       // properties goes here.
    }

    Class D
    {
        // properties goes here.
    }

   ....

   private ClassA methodX
   {
       // code goes here
   }  

   private ClassB methodY
   {
       // code goes here
   }

   private ClassC methodZ
   {
       // code goes here
   }

   ....
}

The classes B, C and D are classes that hold only properties. They don't express any behaviour through a public method. My problem about this approach is that the code of class A is too huge. So the future maintainance of class A will be difficult.

My question is should I remove the classes B, C and D to seperate files or should I leave them there as they are in class A?

Is there a better approach to handle the above problem?

One of my concerns, if I should put this code to separate files, is that I have also other classes like class A. So, there would be a significant increase in the number of files that my application has.

Thanks in advance for any help.

Upvotes: 1

Views: 91

Answers (1)

David Arno
David Arno

Reputation: 43254

If you move them out of class A, into their own files and make them internal classes, this will achieve both keeping them private (with respect to other assemblies) and keep your classes at a more manageable size.

From experience, large numbers of files are not a problem as long as your classes are well named and the files are organised into sub-folders, with matching namespaces.

Upvotes: 2

Related Questions