I'm building a large Desktop application, which will have a range of functionality, for each I wish to have a specific class.

I'm thinking of using a nested class structure to modularize the code and ensure separation of interface vs implementation:

class Manager
    Manager(); //Initialise *t and *wapi in constructor
    ~Manager(); //Delete *t and *wapi in destructor
    class Transport;
    Transport *t;
    class WinAPI;
    WinAPI *wapi;

class Manager::Transport
    Transport(); //Initialise *tcp and *http in constructor
    ~Transport(); //Delete *tcp and *http in destructor
    class TCPSocket;
    TCPSocket *tcp;
    class HTTP;
    HTTP *http;

class Manager::Transport::TCPSocket {};
class Manager::Transport::HTTP {};

class Manager::WinAPI 

This is the first time I've built a large embedded application - are there any issues/other considerations I should consider before taking this approach?

  • 5
    As a (sort of) aside, a class named just "Manager" makes me immediately wonder whether this might not be some close relative of a God Class. Mar 8, 2017 at 17:56
  • 1
    You'll want to define or delete the copy-constructor and/or assignment operator (and the move versions of those) to avoid certain bugs. Look up the Rule of Three / Rule of Five.
    – Sjoerd
    Mar 9, 2017 at 15:07

1 Answer 1


Immediate questions are:

  1. Are TCP sockets and HTTP connections really specific to your Manager::Transport nested class?
  2. How will you unit test them if they're not accessible outside Manager?
  3. Will anything other than a Manager ever need a Transport?

to which at a guess I'd probably answer No, With unnecessary difficulty, and Maybe, respectively.

You don't need this nesting to modularize the code - if anything it seems to have encouraged moving unrelated declarations into the same place.

Socket wrapper, and logical connection objects, look like part of a platform abstraction layer. This would normally go below your business object layer, not inside it.

  • 2
    "Below" and "Inside" are basically the same thing, from the perspective of abstraction. I think the question is more about encapsulation. If the author can do the necessary testing and preserve encapsulation, that is the best. Mar 8, 2017 at 17:57
  • 2
    Even if the fact that your Manager uses Sockets is an implementation detail worth encapsulating, Sockets are a well-understood abstraction independent of what you do with them. I'd normally use nested classes when factoring out implementation details that don't make any sense outside the original class, and could never be used in isolation.
    – Useless
    Mar 9, 2017 at 9:39
  • @Useless thanks for this answer and comments - very helpful. Mar 9, 2017 at 12:35
  • 1
    @Useless bad username! Your comment is very useful! Mar 9, 2017 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.