Reputation: 3887
My current project has two libraries libAAA
and libBBB
.
The former, libAAA
, contains basic math and mechanics for my project (e.g. the rules for chess). The latter, libBBB
, depends on libAAA
but adds GUI elements (e.g. how single figures are drawn).
The executable depends on both, libAAA
and libBBB
. E.g. libBBB
is used to setup the chess game while libBBB
is used to define how it looks (console, qt, gtk,...).
Is it OK to have such redundant dependencies or is it probably bad practice?
edit:
I ask that because I like how easy it is to decouple a GUI representation from the mechanics. E.g. if I would like to change the look or the toolkit, I could just add libHHH
, make another executable and that's it.
Upvotes: 1
Views: 100
Reputation: 406
This is fine.
Let's look at some alternatives:
Pull in all the code from libAAA
into libBBB
: This is alright if libAAA
isn't intended to be used in other contexts, and their respective sizes allow this to be done in a practical manner. In many contexts though, e.g. if libBBB
is much larger and libAAA
is meant as a small reusable library for many projects independently of the UI framework used in libBBB
, this won't work.
Copy the code used by libBBB
into it directly: Please don't. This would mean two separate libraries that do a lot of the same things, two places to update in the future, more confusion for you in the future or for anyone else trying to understand it, etc.
Bring the libBBB
code into the application itself: This is not always possible or practical, depending on your development stack and environment. Many applications may also need libraries that were programmed and compiled in a different language for performance or other reasons.
I'm probably missing a couple other alternative options, but keeping both dependencies despite the redundancy seems the best option to me.
As you stated in the edit, this also allows you to swap out libBBB
for another UI library that also uses libAAA
(or another lib if need be) without tearing down any of your core application code or invalidating any other code in your dependencies.
Upvotes: 1