6

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
{
 public:
 Manager(); //Initialise *t and *wapi in constructor
 ~Manager(); //Delete *t and *wapi in destructor
 private:
 class Transport;
 Transport *t;
 class WinAPI;
 WinAPI *wapi;
};
class Manager::Transport
{
 public:
 Transport(); //Initialise *tcp and *http in constructor
 ~Transport(); //Delete *tcp and *http in destructor
 private:
 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?

asked Mar 8, 2017 at 16:37
2
  • 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. Commented 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. Commented Mar 9, 2017 at 15:07

1 Answer 1

7

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.

answered Mar 8, 2017 at 17:21
4
  • 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. Commented 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. Commented Mar 9, 2017 at 9:39
  • @Useless thanks for this answer and comments - very helpful. Commented Mar 9, 2017 at 12:35
  • 1
    @Useless bad username! Your comment is very useful! Commented Mar 9, 2017 at 17:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.