{"id":1975,"date":"2020-09-20T12:24:06","date_gmt":"2020-09-20T09:24:06","guid":{"rendered":"https:\/\/www.cs.ubbcluj.ro\/~bufny\/?p=1975"},"modified":"2022-01-10T00:18:22","modified_gmt":"2022-01-09T22:18:22","slug":"should-decorators-preserve-the-component-interface","status":"publish","type":"post","link":"https:\/\/www.cs.ubbcluj.ro\/~bufny\/should-decorators-preserve-the-component-interface\/","title":{"rendered":"Should Decorators Preserve the Component Interface?"},"content":{"rendered":"<p>Preprint, <a href=\"https:\/\/arxiv.org\/abs\/2009.06414\" target=\"_blank\" rel=\"noopener noreferrer\">arXiv:2009.06414<\/a> [cs.SE], September 2020.<\/p>\n<p><strong>Cite as<\/strong><\/p>\n<pre class=\"nums:false wrap:on highlight:false\">V. Niculescu, A. Sterca, D. Bufnea, \"Should Decorators Preserve the Component Interface?\", arXiv:2009.06414 [cs.SE], September 2020<\/pre>\n<p><strong>Full paper<\/strong><\/p>\n<p><img decoding=\"async\" style=\"border: none; vertical-align: text-bottom;\" src=\"https:\/\/www.cs.ubbcluj.ro\/~bufny\/wp-content\/uploads\/pdf.png\" alt=\"\" \/> <a href=\"https:\/\/arxiv.org\/pdf\/2009.06414.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">Should Decorators Preserve the Component Interface?<\/a><\/p>\n<p><strong>Authors<\/strong><\/p>\n<p>Virginia Niculescu*, Adrian Sterca*, Darius Bufnea*<br \/>\n* Department of Computer Science, Faculty of Mathematics and Computer Science, Babe\u0219-Bolyai University of Cluj-Napoca, Romania<\/p>\n<p><strong>Abstract<\/strong><br \/>\nDecorator design pattern is a well known pattern that allows dynamical attachment of additional functionality to an object. Decorators have been proposed as flexible alternative to subclassing for extending functionality. Still, the Decorator pattern has certain limitations, especially related to the fact that in its classical form it is constrained to a single interface, which is implicitly defined by the type of the concrete components that we intend to decorate. Another problem associated to the Decorator pattern is related to the linear composition of the decorations, which could lead to problems in accessing the newly added responsibilities. In this context, the paper presents variants of the Decorator pattern: MixDecorator and D2Decorator, and a variant specific only to C++ language based on templates &#8211; HybridDecorator. MixDecorator could be considered a new enhanced version of the Decorator pattern that eliminates some constraints of the Decorator pattern, but also it could be used as a base of a general extension mechanism. The main advantage of using MixDecorator is that it allows direct access to all newly added responsibilities, and so, we may combine different interface-responsibilities (newly added public methods) and operate with them directly and in any order, hiding the linear composition of the decorations. D2Decorator is a variant based on a double-dispatch mechanism. The C++ metaprogramming mechanism based on templates allows an interesting hybrid variant of the Decorator &#8211; HybridDecorator, which mixes on-demand defined inheritance with composition. Using these variants of the Decorator pattern we are not longer limited to one single interface; the set of the messages that could be sent to an object could be enlarged, and so, we may consider that using them, we can dynamically change the type of objects.<\/p>\n<p><strong>Key words<\/strong><\/p>\n<p>OOP; design patterns; decorator; interface; responsibility; extensibility.<\/p>\n<p><strong>BibTeX bib file<\/strong><\/p>\n<p><img decoding=\"async\" style=\"border: none; vertical-align: text-bottom;\" src=\"https:\/\/www.cs.ubbcluj.ro\/~bufny\/wp-content\/uploads\/bib.png\" alt=\"\" \/> <a href=\"https:\/\/www.cs.ubbcluj.ro\/~bufny\/wp-content\/uploads\/mixdecorator2020.bib\" target=\"_blank\" rel=\"noopener noreferrer\">mixdecorator2020.bib<\/a><\/p>\n<pre class=\"lang:tex url:wp-content\/uploads\/mixdecorator2020.bib nums:false\"><\/pre>\n<p><strong>References<\/strong><\/p>\n<ul>\n<li>Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. <em>Design Patterns: Elements of Reusable Object Oriented Software<\/em>. Addison Wesley, Oct 1994.<\/li>\n<li>Alan Shalloway and James R. Trott. <em>Design Patterns Explained: A New Perspective on Object Oriented Design<\/em>, 2<sup>nd<\/sup> Edition. Addison Wesley, 2004.<\/li>\n<li>Martin B\u00fcchi and Wolfgang Weck. <em>Generic wrappers<\/em>. In Elisa Bertino, editor, ECOOP 2000 \u2014 Object-Oriented Programming, pages 201\u2013225, Berlin, Heidelberg, 2000. Springer Berlin Heidelberg.<\/li>\n<li>G\u00fcnter Kniesel, Tobias Rho, and Stefan Hanenberg. <em>Evolvable pattern implementations need generic aspects<\/em>. In RAM-SE, 2004.<\/li>\n<li>Aminata Saban\u00e9, Yann-Ga\u00ebl Gu\u00e9h\u00e9neuc, Venera Arnaoudova, and Giuliano Antoniol. <em>Fragile base-class problem, problem?<\/em> Empirical Software Engineering, 22:2612\u20132657, 2016.<\/li>\n<li>Joshua Bloch. Effective Java, 3<sup>rd<\/sup> Edition. Addison-Wesley Professional, 2017.<\/li>\n<li>Virginia Niculescu. <em>Mixdecorator: An enhanced version of decorator pattern<\/em>. In Proceedings of the 20<sup>th<\/sup> European Conference on Languages of Programs, EuroPLoP &#8217;15, pages 36:1\u201336:12, New York, USA, 2015. ACM.<\/li>\n<li>Oracle. <em>Java SE 8: Implementing default methods in interfaces<\/em>. [online: <a href=\"http:\/\/www.oracle.com\/webfolder\/technetwork\/tutorials\/obe\/java\/JavaSE8DefaultMethods\/JavaSE8DefaultMethods.html\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">http:\/\/www.oracle.com\/webfolder\/technetwork\/tutorials\/obe\/java\/JavaSE8DefaultMethods\/JavaSE8DefaultMethods.html<\/a>], 2018. Accessed: July 20, 2020.<\/li>\n<li>Microsoft. <em>What&#8217;s new in C# 8.0<\/em>. [online: <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/whats-new\/csharp-8\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/whats-new\/csharp-8<\/a>], 2020. Accessed: July 20, 2020.<\/li>\n<li>Kotlin. <em>Kotlin &#8211; extension methods<\/em>. [online: <a href=\"https:\/\/kotlinlang.org\/docs\/reference\/extensions.html\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">https:\/\/kotlinlang.org\/docs\/reference\/extensions.html<\/a>], 2020. Accessed: August 07, 2020.<\/li>\n<li>Viviana Bono, Enrico Mensa, and Marco Naddeo. <em>Trait-oriented programming in Java 8<\/em>. In Proceedings of the 2014 International Conference on Principles and Practices of Programming on the Java Platform: Virtual Machines, Languages, and Tools, PPPJ &#8217;14, pages 181\u2013186, New York, NY, USA, 2014. ACM.<\/li>\n<li>Microsoft. <em>Extension methods (C# programming guide)<\/em>. [online: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/bb383977.aspx\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">https:\/\/msdn.microsoft.com\/en-us\/library\/bb383977.aspx<\/a>], 2015. Accessed: February 14, 2020.<\/li>\n<li>Andrei Alexandrescu. <em>Modern C++ design: generic programming and design patterns applied<\/em>. Addison-Wesley, 2001.<\/li>\n<li>David Abrahams and Aleksey Gurtovoy. <em>C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond<\/em>. Addison-Wesley, 2003.<\/li>\n<li>Y. Smaragdakis and D. Batory. <em>Mixin-based programming in C++<\/em>. In Proceedings of the Second International Symposium on Generative and Component-Based Software Engineering, 2000.<\/li>\n<li>Gilad Bracha and William Cook. <em>Mixin-based inheritance<\/em>. In Proceedings of the European Conference on Object-oriented Programming on Object-oriented Programming Systems, Languages, and Applications, OOPSLA\/ECOOP &#8217;90, pages 303\u2013311, New York, NY, USA, 1990. ACM.<\/li>\n<li>Virginia Niculescu. <em>Efficient decorator pattern variants through C++ policies<\/em>. In Proceedings of the 15<sup>th<\/sup> International Conference on Evaluation of Novel Approaches to Software Engineering &#8211; Volume 1: ENASE,, pages 281\u2013288. INSTICC, SciTePress, 2020.<\/li>\n<li>Nathanael Sch\u00e4rli, St\u00e9phane Ducasse, Oscar Nierstrasz, and Andrew P. Black. <em>Traits: Composable units of behaviour<\/em>. In ECOOP, 2002.<\/li>\n<li>Scala. <em>Scala documentation: Traits<\/em>. [online: <a href=\"http:\/\/docs.scala-lang.org\/tour\/traits.html\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">http:\/\/docs.scala-lang.org\/tour\/traits.html<\/a>], 2015. Accessed: July 20, 2020.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Preprint, arXiv:2009.06414 [cs.SE], September 2020. Cite as V. Niculescu, A. Sterca, D. Bufnea, &#8220;Should Decorators Preserve the Component Interface?&#8221;, arXiv:2009.06414 [cs.SE], September 2020 Full paper Should Decorators Preserve the Component Interface? Authors Virginia Niculescu*, Adrian Sterca*, Darius Bufnea* * Department&hellip; <a href=\"https:\/\/www.cs.ubbcluj.ro\/~bufny\/should-decorators-preserve-the-component-interface\/\" class=\"more-link\">Continue Reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[110],"tags":[],"_links":{"self":[{"href":"https:\/\/www.cs.ubbcluj.ro\/~bufny\/wp-json\/wp\/v2\/posts\/1975"}],"collection":[{"href":"https:\/\/www.cs.ubbcluj.ro\/~bufny\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cs.ubbcluj.ro\/~bufny\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cs.ubbcluj.ro\/~bufny\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cs.ubbcluj.ro\/~bufny\/wp-json\/wp\/v2\/comments?post=1975"}],"version-history":[{"count":11,"href":"https:\/\/www.cs.ubbcluj.ro\/~bufny\/wp-json\/wp\/v2\/posts\/1975\/revisions"}],"predecessor-version":[{"id":2219,"href":"https:\/\/www.cs.ubbcluj.ro\/~bufny\/wp-json\/wp\/v2\/posts\/1975\/revisions\/2219"}],"wp:attachment":[{"href":"https:\/\/www.cs.ubbcluj.ro\/~bufny\/wp-json\/wp\/v2\/media?parent=1975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cs.ubbcluj.ro\/~bufny\/wp-json\/wp\/v2\/categories?post=1975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cs.ubbcluj.ro\/~bufny\/wp-json\/wp\/v2\/tags?post=1975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}