{"id":359,"date":"2018-02-23T00:01:08","date_gmt":"2018-02-23T00:01:08","guid":{"rendered":"http:\/\/cppdepend.com\/blog\/?p=359"},"modified":"2018-02-23T00:01:08","modified_gmt":"2018-02-23T00:01:08","slug":"the-hidden-cost-of-a-high-coupling-with-a-c-framework","status":"publish","type":"post","link":"https:\/\/cppdepend.com\/blog\/the-hidden-cost-of-a-high-coupling-with-a-c-framework\/","title":{"rendered":"The hidden cost of a high coupling with a C++ framework."},"content":{"rendered":"<p>Many C++ libraries and frameworks are available and using them can accelerate the development of your projects.\u00a0In this post we will explore the drawback of\u00a0having a\u00a0C++ application highly dependent with an external framework. But first what&#8217;s the difference between a library and a framework? And why the high coupling with a framework could have more drawbacks than a high coupling with a library?<!--more--><\/p>\n<p>Here&#8217;s from this <a href=\"https:\/\/www.programcreek.com\/2011\/09\/what-is-the-difference-between-a-java-library-and-a-framework\/\">post <\/a>an interesting comparison between them:<\/p>\n<pre>The key difference between a library and a framework is \"Inversion of Control\". When you call a method from a library, you are in control. But with a framework, the control is inverted: the framework calls you.<\/pre>\n<p>And the framework could be defined like that:<\/p>\n<pre>It defines a skeleton where the application defines its own features to fill out the skeleton. In this way, your code will be called by the framework when appropriately. The benefit is that developers do not need to worry about if a design is good or not, but just about implementing domain specific functions.<\/pre>\n<p>To resume the framework is more intrusive than a library and it could influence your application architecture and design.<\/p>\n<p>For example Qt and MFC are two known C++ frameworks, here are their definitions from their websites:<\/p>\n<p>Qt:<\/p>\n<pre><em>Qt<\/em>\u00a0is a cross-platform development\u00a0<strong><em>framework<\/em>\u00a0<\/strong>enabling your team to deploy a single codebase providing common APIs across all supported platforms.<\/pre>\n<p>And MFC:<\/p>\n<pre>Your work with the Microsoft Foundation Class (MFC) Library <strong>framework<\/strong> is based largely on a few major classes and several Visual C++ tools. Some classes encapsulate a large portion of the Win32 application programming interface (API). Other classes encapsulate application concepts such as documents, views, and the application itself. Still others encapsulate OLE features and ODBC and DAO data-access functionality.<\/pre>\n<p>Because the framework is more intrusive. If an application is highly coupled with it,\u00a0 almost all the actors of the project will be impacted.<\/p>\n<p><em><strong>Human resource recruiter:<\/strong><\/em><br \/>\nIf a project is highly coupled with an external framework, almost each developer must master this framework which makes\u00a0the task of recruiting new developers to integrate the project more difficult. Indeed, we must search for C++ developers\u00a0who have some background about the framework used.<\/p>\n<p><em><strong>Architect and designer:<\/strong><\/em><br \/>\nWhen the project is highly coupled with an external framework, we lose of flexibility, and any evolution, migration or adaptation of the project became more complicated.<\/p>\n<p><em><strong>Developer:<\/strong><\/em><br \/>\nAny framework has its difficulties and force every developer to master it because it\u2019s highly coupled with the project. It will add more\u00a0complexity to the project and it will have a big impact on the development time and quality.<\/p>\n<p><em><strong>Tester:<\/strong><\/em><br \/>\nIt\u2019s very difficult to isolate just our code and test it if it\u2019s highly coupled with other frameworks. Sometimes the tester need to do some\u00a0extra works to test the application.<\/p>\n<p>It\u2019s nice to use an external framework to accelerate the development of our project.\u00a0However, we must use them carefully and avoid as possible unnecessary coupling.<\/p>\n<p>Let\u2019s analyze some C++ open source projects and discover what skills needed for a developer who want to integrate their development team.<\/p>\n<p><strong>Case I: Emule project (http:\/\/www.emule-project.net)<\/strong><\/p>\n<p>After the analysis of the emule project with CppDepend we observe that it uses mainly the MFC framework\u00a0 and the windows API .<\/p>\n<p><a href=\"http:\/\/1.bp.blogspot.com\/_tWDA5bNBNHI\/Sk0exaPADRI\/AAAAAAAAADc\/k9Wl7SbmOC8\/s1600-h\/emuledep.PNG\"><img decoding=\"async\" id=\"BLOGGER_PHOTO_ID_5353969366218050834\" src=\"http:\/\/1.bp.blogspot.com\/_tWDA5bNBNHI\/Sk0exaPADRI\/AAAAAAAAADc\/k9Wl7SbmOC8\/s800\/emuledep.PNG\" alt=\"\" border=\"0\" \/><\/a><\/p>\n<p>Let\u2019s see if the project is highly coupled with MFC , for that we can ask CppDepend which methods use MFC, here\u2019s the result in the <a href=\"https:\/\/www.cppdepend.com\/Doc_Treemap\">treemap <\/a>graph:<\/p>\n<p><a href=\"http:\/\/2.bp.blogspot.com\/_tWDA5bNBNHI\/Sk0gbHpqMqI\/AAAAAAAAADk\/l7K-wK0b4q0\/s1600-h\/Mfcused.PNG\"><img decoding=\"async\" id=\"BLOGGER_PHOTO_ID_5353971182295724706\" src=\"http:\/\/2.bp.blogspot.com\/_tWDA5bNBNHI\/Sk0gbHpqMqI\/AAAAAAAAADk\/l7K-wK0b4q0\/s800\/Mfcused.PNG\" alt=\"\" border=\"0\" \/><\/a><\/p>\n<p>We observe that almost all the methods use the \u00a0MFC framework which makes the emule codebase highly coupled with it.<\/p>\n<p>We can also search for the \u00a0mostly used MFC classes:<\/p>\n<div><a href=\"http:\/\/4.bp.blogspot.com\/_tWDA5bNBNHI\/Sk0hL-np_fI\/AAAAAAAAADs\/slZ7Re8GCN0\/s1600-h\/mfctypes.PNG\"><img decoding=\"async\" id=\"BLOGGER_PHOTO_ID_5353972021684993522\" src=\"http:\/\/4.bp.blogspot.com\/_tWDA5bNBNHI\/Sk0hL-np_fI\/AAAAAAAAADs\/slZ7Re8GCN0\/s800\/mfctypes.PNG\" alt=\"\" border=\"0\" \/><\/a><\/div>\n<div><\/div>\n<p>MFC is used everywhere in the project, it uses the\u00a0Gui components, Internet, Archive and Containers classes.<\/p>\n<p>This high coupling has two major drawbacks:<\/p>\n<ul>\n<li>We can&#8217;t reuse easily the emule algorithm in other projects. We are forced to also use the MFC library if we want to reuse it.<\/li>\n<li>Any developer who want to integrate the emule project must master the MFC library.<\/li>\n<\/ul>\n<p><strong>Case II: OpenSTA project (http:\/\/sourceforge.net\/projects\/opensta\/)<\/strong><\/p>\n<p><a href=\"http:\/\/2.bp.blogspot.com\/_tWDA5bNBNHI\/Sk0kQXNRkxI\/AAAAAAAAAD8\/yz7cp4g905Q\/s1600-h\/opensta.PNG\"><img loading=\"lazy\" decoding=\"async\" id=\"BLOGGER_PHOTO_ID_5353975395539587858\" src=\"http:\/\/2.bp.blogspot.com\/_tWDA5bNBNHI\/Sk0kQXNRkxI\/AAAAAAAAAD8\/yz7cp4g905Q\/s800\/opensta.PNG\" alt=\"\" width=\"660\" height=\"221\" border=\"0\" \/><\/a><\/p>\n<p>OpenSTA is divided into multiple projects and here are some project dependencies:<\/p>\n<div><a href=\"http:\/\/4.bp.blogspot.com\/_tWDA5bNBNHI\/Sk0lphDOuQI\/AAAAAAAAAEE\/v1d7MZqnmFo\/s1600-h\/dependency.PNG\"><img decoding=\"async\" id=\"BLOGGER_PHOTO_ID_5353976927190169858\" src=\"http:\/\/4.bp.blogspot.com\/_tWDA5bNBNHI\/Sk0lphDOuQI\/AAAAAAAAAEE\/v1d7MZqnmFo\/s800\/dependency.PNG\" alt=\"\" border=\"0\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<p>Divide the project into many modules can be very advantageous, it\u2019s better to isolate the functionalities so we can use them in other projects and it simplify the complexity of the project.<\/p>\n<p>Which projects use MFC?<\/p>\n<p><a href=\"http:\/\/3.bp.blogspot.com\/_tWDA5bNBNHI\/Sk0nFGp_jdI\/AAAAAAAAAEU\/7JJTGTDlBnE\/s1600-h\/openmfcused.PNG\"><img decoding=\"async\" id=\"BLOGGER_PHOTO_ID_5353978500652961234\" src=\"http:\/\/3.bp.blogspot.com\/_tWDA5bNBNHI\/Sk0nFGp_jdI\/AAAAAAAAAEU\/7JJTGTDlBnE\/s800\/openmfcused.PNG\" alt=\"\" border=\"0\" \/><\/a><\/p>\n<p>We observe that not all the projects use the MFC\u00a0 framework and the big ones does not\u00a0use it.<\/p>\n<p>Which MFC classes are used?<\/p>\n<div><a href=\"http:\/\/3.bp.blogspot.com\/_tWDA5bNBNHI\/Sk0mZFvvCbI\/AAAAAAAAAEM\/CG0wJPQ2mxY\/s1600-h\/openmfc.PNG\"><img decoding=\"async\" id=\"BLOGGER_PHOTO_ID_5353977744494365106\" src=\"http:\/\/3.bp.blogspot.com\/_tWDA5bNBNHI\/Sk0mZFvvCbI\/AAAAAAAAAEM\/CG0wJPQ2mxY\/s800\/openmfc.PNG\" alt=\"\" border=\"0\" \/><\/a><\/div>\n<div><\/div>\n<p>OpenSTA uses mainly\u00a0 the OLE classes.<\/p>\n<p>For the OpenSTA project a C++ developer who not master the MFC framework can integrate the project. they are many modules not using directly MFC.<\/p>\n<p><strong>Summary:<\/strong><\/p>\n<p>Isolating the use of the external framework can be very advantageous for all the project actors, try to keep it simple and avoid any unnecessary coupling especially with the business layer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many C++ libraries and frameworks are available and using them can accelerate the development of your projects.\u00a0In this post we will explore the drawback of\u00a0having a\u00a0C++ application highly dependent with an external framework. But first what&#8217;s the difference between a library and a framework? And why the high coupling with a framework could have more &hellip; <a href=\"https:\/\/cppdepend.com\/blog\/the-hidden-cost-of-a-high-coupling-with-a-c-framework\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;The hidden cost of a high coupling with a C++ framework.&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-359","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/359","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/comments?post=359"}],"version-history":[{"count":15,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/359\/revisions"}],"predecessor-version":[{"id":463,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/359\/revisions\/463"}],"wp:attachment":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/media?parent=359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/categories?post=359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/tags?post=359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}