C++ Component Dependencies

K

kk_oop

I've got a question about "component" dependencies in C++. For
this discussion, I'm considering a component to be a group of classes
that implement a service provided to other components via an interface
or via a service request message.

Consider component A and B. B offers a service processWidget. This
service is invoked by A sending a ProcessWidget message to B. The
message is represented by the header file ProcessWidgetMsg.h.

My directory structure is set up so each component has a root
directory named after the component. So in this example, we have peer
directories A and B. Under each of these directories are the
respective component's implementation files or subdirectories
containing implementation files. Let's say in this example, B has a
subdirectory called WidgetProcessor and that contains various .h
and .cpp files that know how to process a Widget.

Here are my questions:

1. If I put a Messages folder under B and store the
ProcessWidgetMsg.h file there, would you consider component A to be
dependent upon component B? I'm thinking it would be, since A needs
a .h file under B's file hierarchy (the ProcessWidgetMsg.h file).

2. If instead of doing that, let's say I created a Messages directory
as a peer to A and B, and I placed the ProcessWidgetMsg.h file there.
Would you still consider A to be dependent on B, since A still
requires B's service? I know there would be no physical dependency in
this case, but would there be utility in documenting that A has a
logical dependency on B?

Thanks for any opinions!

Ken
 
Q

qinghu.liao

Have a progressInterface.h, put it in directory C. Let A depend on C,
and A can
register/unregister/notify instances of progressInterface type
objects, while
B (processWidget) inherits ProgressInterface.
 
E

Erik Wikström

I've got a question about "component" dependencies in C++. For
this discussion, I'm considering a component to be a group of classes
that implement a service provided to other components via an interface
or via a service request message.

Consider component A and B. B offers a service processWidget. This
service is invoked by A sending a ProcessWidget message to B. The
message is represented by the header file ProcessWidgetMsg.h.

My directory structure is set up so each component has a root
directory named after the component. So in this example, we have peer
directories A and B. Under each of these directories are the
respective component's implementation files or subdirectories
containing implementation files. Let's say in this example, B has a
subdirectory called WidgetProcessor and that contains various .h
and .cpp files that know how to process a Widget.

Here are my questions:

1. If I put a Messages folder under B and store the
ProcessWidgetMsg.h file there, would you consider component A to be
dependent upon component B? I'm thinking it would be, since A needs
a .h file under B's file hierarchy (the ProcessWidgetMsg.h file).
Yes.

2. If instead of doing that, let's say I created a Messages directory
as a peer to A and B, and I placed the ProcessWidgetMsg.h file there.
Would you still consider A to be dependent on B, since A still
requires B's service? I know there would be no physical dependency in
this case, but would there be utility in documenting that A has a
logical dependency on B?


The dependency still exist simply because A relies (depends) on a
service provided by B. What you are discussing is just a matter of
organising the code but does not in change the way the code works (or
the dependencies between different parts of the code).
 
C

Chris Gordon-Smith

I've got a question about "component" dependencies in C++. For
this discussion, I'm considering a component to be a group of classes
that implement a service provided to other components via an interface
or via a service request message.

Consider component A and B. B offers a service processWidget. This
service is invoked by A sending a ProcessWidget message to B. The
message is represented by the header file ProcessWidgetMsg.h.

My directory structure is set up so each component has a root
directory named after the component. So in this example, we have peer
directories A and B. Under each of these directories are the
respective component's implementation files or subdirectories
containing implementation files. Let's say in this example, B has a
subdirectory called WidgetProcessor and that contains various .h
and .cpp files that know how to process a Widget.

Here are my questions:

1. If I put a Messages folder under B and store the
ProcessWidgetMsg.h file there, would you consider component A to be
dependent upon component B? I'm thinking it would be, since A needs
a .h file under B's file hierarchy (the ProcessWidgetMsg.h file).

2. If instead of doing that, let's say I created a Messages directory
as a peer to A and B, and I placed the ProcessWidgetMsg.h file there.
Would you still consider A to be dependent on B, since A still
requires B's service? I know there would be no physical dependency in
this case, but would there be utility in documenting that A has a
logical dependency on B?

It seems to me that by using a message you have made A and B loosely
coupled. You can change B without impacting A, and the system will still
work provided the new B provices the same service. Presumably the service
works by B picking up messages from A from some kind of queue. One could
say that in this situation, your system as a whole needs a service to
process the messages that A produces. However, A itself is not dependent on
B, and B is not dependent on A, because neither is aware of the other. They
only know about the messages.

A will be perfectly happy so long as it can put messages on the queue, and B
will be perfectly happy so long as it take messages from the queue.

In short:-
* A and B can be changed independently, and so are not dependent on one
another
* The system as a whole will only work if something (eg A) produces
messages in the correct format, and something else (eg B) consumes the
messages and provides the service. This is not really a dependency of A on
B; its a need of the system as a whole for messages to be produced and
consumed in a certain way.

If you were to draw a diagram showing 'using' relationships, both A and B
would use the message, but neither would use the other:-

A------ Uses ---------> Message <-------- Uses ---------- B

Chris Gordon-Smith
www.simsoup.info
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top