Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 81389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:27:08+00:00 2026-05-10T21:27:08+00:00

Suppose I have a class ‘Application’. In order to be initialised it takes certain

  • 0

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  {    Application(ApplicationSettings settings)     {        //Do initialisation here    } }  class ApplicationSettings  {    //Settings related methods and properties here } 

Implementation 2:

class Application  {    Application(Application.Settings settings)     {        //Do initialisation here    }     class Settings     {       //Settings related methods and properties here    } } 

To me, the second approach is very much preferable. It is more readable because it strongly emphasises the relation between the two classes. When I write code to instantiate Application class anywhere, the second approach is going to look prettier.

Now just imagine the Settings class itself in turn had some similarly ‘related’ class and that class in turn did so too. Go only three such levels and the class naming gets out out of hand in the ‘non-nested’ case. If you nest, however, things still stay elegant.

Despite the above, I’ve read people saying on StackOverflow that nested classes are justified only if they’re not visible to the outside world; that is if they are used only for the internal implementation of the containing class. The commonly cited objection is bloating the size of containing class’s source file, but partial classes is the perfect solution for that problem.

My question is, why are we wary of the ‘publicly exposed’ use of nested classes? Are there any other arguments against such use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:27:09+00:00Added an answer on May 10, 2026 at 9:27 pm

    I think it’s fine. This is basically the builder pattern, and using nested classes works pretty well. It also lets the builder access private members of the outer class, which can be very useful. For instance, you can have a Build method on the builder which calls a private constructor on the outer class which takes an instance of the builder:

    public class Outer {     private Outer(Builder builder)     {         // Copy stuff     }      public class Builder     {         public Outer Build()         {             return new Outer(this);         }     } } 

    That ensures that the only way of building an instance of the outer class is via the builder.

    I use a pattern very much like this in my C# port of Protocol Buffers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 70k
  • Answers 70k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Another idea: If you have an own root server or… May 11, 2026 at 1:06 pm
  • added an answer Your colleague is correct. As the data is stored in… May 11, 2026 at 1:06 pm
  • added an answer IMessageFilter.PreFilterMessage() is only called for messages in the message queue.… May 11, 2026 at 1:06 pm

Related Questions

Suppose I have a class module clsMyClass with an object as a member variable.
Suppose I have a class with some attributes. How is it best (in the
Suppose I have a class 'Application'. In order to be initialised it takes certain
Suppose I have a class public class MyClass { private Set<String> set = new
For example, suppose I have a class: class Foo { public: std::string& Name() {
Suppose I need to have a class which wraps a priority queue of other

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.