tags:

views:

111

answers:

1

Most programing languages have 'include library into your code' function but where is function 'include your code into library'?

I Mean push into other files from the source, rather than pull into from the consuming files.

Idea is simple - we have a library A with class B we want to extend B with some C functions but we do not want to do it by extending from B, but by extending B.

So if we had library like DLL with functions and we would like to add functions to that DLL with out crating new DLL, and keeping ability to call that new functions as if we were calling that first DLL.

Point is not in having DLL sources and modifying tham, and not in wrapping around all functions in that dll just for adding few new functions creating new dll, but in adding functionality into existing dll and getting that modified DLL back. With no wrapping around but with inserting inside.

If you find this question a QUESTION, please vote for reopening.

If you have something to add - please add - it's comunity wiki.

+1  A: 

This depends a lot on the programming language at hand.

In C++, any module (because there are no modules) can add content to any namespace. You can link two different DLL's both adding members to the same namespace.

C# takes it a step further, not only can anyone add to any namespace, but you can use "extension methods" to add methods to existing classes.

In Ruby, reopening classes is simply done by defining part of the class elsewhere, effectively having multiple definitions of a class. But they all refer to the same class, so at runtime, they all end up in the same one.

In Lua you can reopen modules with the "module" function and add anything you want.

None of this actually modifies the "source" of the original code - but they offer natural, seamless extensions to it, so it's probably as close as you get.