How bridge pattern help for decoupling the implmentation and avoid recompiling on client side

StackOverflow https://stackoverflow.com/questions/22674613

  •  22-06-2023
  •  | 
  •  

Question

I have some confusion in the benefit of recompiling from the bridge pattern.

For example, why making an abstract implementation interface will help with client code not recompiling when we change the implementation? I guess for the client that includes "window.h" which includes "windowImp.h" will eventually adding all parts from these two classes to the client code during the preprocessor process.

can someone please explain the benefit in terms of how the compiler compile each unit and when the implementation is changed, why it just required a client to relink?

Was it helpful?

Solution

The compiler basically compiles each cpp file individually and then links the output. If you now change one of the includes used in this cpp or the cpp itself, you need to re-compile that cpp (if you do an incremental build).

Let's assume your cpp file foo.cpp includes a header bar.h. bar.h defines a class foobar. If you now change a private variable (an implementation detail) of foobar, you need to recompile foo.cpp. If you make an abstract base class (e.g. Ifoobar in ibar.h), foo.cpp can now include ibar.h. If you now change an implementation detail of bar.h it does not force a recompile of foo.cpp. Assume that this class foobar is used in thousands of files and you saved a lot of compilation time.

Regards Tobias

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top