I am currently creating an addon that will serve as the basis for other addons, an abstract addon if you will.
So it will be used by multiple addons that will build on top of it, and there may be multiple such loading for a single toon.
Now my addon contains multiple files, which include a few widgets and locale files for each language among others.
So my concern is that I don't want all these files to be loaded again and again for each separate addon using it.
I see two options for solving this each with their own caveats and I would appreciate any input on which you would consider best practice or if a third better option exists.
1. Implement as a Library.
Using Libstub in the main code file which I would then load last and in it set a global that I can check the existence of at the start of locale files, widget lua files etc, and abort further loading if that global exists (versioned).
The main caveat I see here is that I can't see a way to do this check for widget xml files. Plus it is a bit cumbersome.
2. Implement as standalone addon
Main caveat here is that end users would have to download my addon themselves, in addition to the addons using it, and keep it up to date.
I apologize for the rather long post, but hope some will have thoughts on the matter.
With a library you will not be able to use any SavedVariables. Moreover, as you stated it, there is no way to prevent xml widgets to be loaded but you can do in Lua almost all you can do in XML, the notable exception being XML templates. Finally, instead of using a global you could use a variable in the private table of the hosting addon.
The other thing you should think about is splitting your common "addon" in smaller libraries, instead of a monolithic one. This could help design them as libraries.
Curse client should be able to resolve hard dependencies, automatically downloading required dependencies. However that seems to require some additional "work" as putting the addon into the .pkgmeta as a required dependency is not enough.
I also had to add it as a default required dependency in the web interface (Project management -> Repository -> Edit default relationships).
Assuming you want the default setup, where an addon has both the no-lib-strip and libs-included versions, you shouldn't need to edit the default relationships. And except for LibDataBroker-1.1, you also shouldn't need to hard embed libraries or other addons. The following is my setup for addons, and nobody has said I did things horribly wrong.
Please note that I am using keyword substitutions in the ToC, no-lib-strip, and LDB is hard-embedded. In the pkgmeta, you should never ever use tabs but rather direct spaces with the space bar.
For LDB, create the libs folder in your addon, download and copy the unzipped folder into your libs folder (you can see the path I chose in the ToC above), then using Hg, Git, or SVN, add the libs folder like you would any other file or folder to your project. The tools-used line in pkgmeta takes care of the rest, updating LDB if there is an update.
Once you tag a Beta or Release version, the project page will automatically update with the dependencies and you are set. The initial alpha commits will not show this; just letting you know ahead of time.
You might also note the OptionsDeps line in the Toc: LibDataBroker is not listed because it is not an optional dependency. You can specify other addons or modules of addons. For example, I could specify OptionalDeps: PitBull4_Portrait or simply PitBull4. LDB does not need the RequiredDeps line in the above setup. The Curseforge/WoWAce Packager takes care of that for you.
Sorry if that was unclear, I was talking about making the "Core" or "Framework" a separate Addon that the implementing Addons can hard-depend on. This way the "Core" will only ever be installed and run once.