Repository: polygene-website Updated Branches: refs/heads/asf-site 9a1a05624 -> bb9c9971b
http://git-wip-us.apache.org/repos/asf/polygene-website/blob/bb9c9971/content/java/2017/tutorials.html ---------------------------------------------------------------------- diff --git a/content/java/2017/tutorials.html b/content/java/2017/tutorials.html new file mode 100644 index 0000000..ae5aadd --- /dev/null +++ b/content/java/2017/tutorials.html @@ -0,0 +1,145 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Tutorials</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1" /><link rel="home" href="index.html" title="" /><link rel="up" href="index.html" title="" /><link rel="prev" href="related.html" title="Related publications & projects" /><link rel="next" href="two-minutes-intro.html" title="Polygene⢠in 2 minutes" /> + + + <meta charset="utf-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> + <meta name="description" content=""> + <meta name="author" content=""> + <link rel="icon" href="../../favicon.ico"> + + <title>Starter Template for Bootstrap</title> + + <!-- Bootstrap core CSS --> + <link href="bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet"> + + <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> + <link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet"> + + <!-- Custom styles for this template --> + <link href="css/polygene-ng.css" rel="stylesheet"> + + <!-- Just for debugging purposes. Don't actually copy these 2 lines! --> + <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]--> + <script src="js/ie-emulation-modes-warning.js"></script> + + <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> + <!--[if lt IE 9]> + <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> + <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> + <![endif]--> + +<!-- favicon --> + +<link rel="shortcut icon" href="http://polygene.apache.org/favicon.ico" type="image/vnd.microsoft.icon" /> +<link rel="icon" href="http://polygene.apache.org/favicon.ico" type="image/x-icon" /> + +<!-- style --> + +<link href="css/shCore.css" rel="stylesheet" type="text/css" /> +<link href="css/shCoreEclipse.css" rel="stylesheet" type="text/css" /> +<link href="css/shThemeEclipse.css" rel="stylesheet" type="text/css" /> +<!--<link href="css/polygene.css" rel="stylesheet" type="text/css" />--> + +<!-- Syntax Highlighter --> + +<script type="text/javascript" src="js/shCore.js"></script> +<script type="text/javascript" src="js/shBrushJava.js"></script> +<script type="text/javascript" src="js/shBrushScala.js"></script> +<script type="text/javascript" src="js/shBrushJScript.js"></script> +<script type="text/javascript" src="js/shBrushBash.js"></script> +<script type="text/javascript" src="js/shBrushPlain.js"></script> +<script type="text/javascript" src="js/shBrushXml.js"></script> +<script type="text/javascript" src="js/shBrushGroovy.js"></script> +<script type="text/javascript" src="js/shBrushPython.js"></script> +<script type="text/javascript" src="js/shBrushRuby.js"></script> +<script type="text/javascript" src="js/shBrushCSharp.js"></script> + +<script type="text/javascript"> + SyntaxHighlighter.defaults['tab-size'] = 4; + SyntaxHighlighter.defaults['gutter'] = false; + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all() +</script> + +<!-- JQuery --> + +<script type="text/javascript" src="js/jquery-1.6.4.min.js"></script> + +<!-- Image Scaler --> + +<script type="text/javascript" src="js/imagescaler.js"></script> + +<!-- Table Styler --> + +<script type="text/javascript" src="js/tablestyler.js"></script> + +<!-- Apache Polygene WebSite Progressive Enhancement --> + +<link href="css/progressive-enhancement.css" rel="stylesheet" type="text/css" /> +<script type="text/javascript" src="js/jquery.scrollTo-1.4.2.js"></script> +<script type="text/javascript" src="js/progressive-enhancement.js"></script> + +<!-- Analytics --> + <script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-62007352-1']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + </script> + + </head><body><div xmlns="" xmlns:exsl="http://exslt.org/common" class="logo"><a href="index.html"><img src="images/logo-standard.png" /></a></div><nav xmlns="" xmlns:exsl="http://exslt.org/common" class="navbar navbar-inverse navbar-fixed-top"><div class="container"><div class="navbar-header"><a class="navbar-brand" href="#">Apache<br />Polygene + </a></div><div id="navbar" class="collapse navbar-collapse"><span class="nav navbar-nav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl class="toc"><dt><span class="section"><a href="index.html#home">Polygeneâ¢</a></span></dt><dt><span class="section"><a href="intro.html">Introduction</a></span></dt><dt><span class="section"><span xmlns="" href="tutorials.html">Tutorials</span></span></dt><dt><span class="section"><a href="javadocs.html">Javadoc</a></span></dt><dt><span class="section"><a href="samples.html">Samples</a></span></dt><dt><span class="section"><a href="core.html">Core</a></span></dt><dt><span class="section"><a href="libraries.html">Libraries</a></span></dt><dt><span class="section"><a href="extensions.html">Extensions</a></span></dt><dt><span class="section"><a href="tools.html">Tools</a></span></dt><dt><span class="section"><a href="glossary.html">Glossary </a></span></dt></dl></div></span></div></div></nav><div xmlns="" xmlns:exsl="http://exslt .org/common" class="sidenav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl class="toc"><dt><span class="section"><span xmlns="" href="tutorials.html#_overview">Overview</span></span></dt><dt><span class="section"><a href="two-minutes-intro.html">Polygene⢠in 2 minutes</a></span></dt><dt><span class="section"><a href="ten-minutes-intro.html">Polygene⢠in 10 minutes</a></span></dt><dt><span class="section"><a href="thirty-minutes-intro.html">Polygene⢠in 30 minutes</a></span></dt><dt><span class="section"><a href="howto-depend-on-polygene.html">Depend on Polygeneâ¢</a></span></dt><dt><span class="section"><a href="howto-assemble-application.html">Assemble an Application</a></span></dt><dt><span class="section"><a href="tut-composites.html">Transient Composites Tutorial</a></span></dt><dt><span class="section"><a href="tut-services.html">Services Composites Tutorial</a></span></dt><dt><span class="section"><a href="howto-contextual-fragments.html">Use contextual frag ments</a></span></dt><dt><span class="section"><a href="howto-leverage-properties.html">Leverage Properties</a></span></dt><dt><span class="section"><a href="howto-create-constraint.html">Create a Constraint</a></span></dt><dt><span class="section"><a href="howto-create-concern.html">Create a Concern</a></span></dt><dt><span class="section"><a href="howto-create-sideeffect.html">Create a SideEffect</a></span></dt><dt><span class="section"><a href="howto-create-entity.html">Create an Entity</a></span></dt><dt><span class="section"><a href="howto-configure-service.html">Configure a Service</a></span></dt><dt><span class="section"><a href="howto-invocation-annotation.html">Use @Invocation</a></span></dt><dt><span class="section"><a href="build-system.html">Polygene⢠Build System</a></span></dt><dt><span class="section"><a href="community-docs.html">Polygene⢠Documentation</a></span></dt><dt><span class="section"><a href="releasing-apache.html">Releasing Polygeneâ¢</a></span></dt>< /dl></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a id="tutorials"></a>Tutorials</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_overview"></a>Overview</h3></div></div></div><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Tip</h3><p>Theses tutorials are based on actual code found in the <code class="literal">tutorials/</code> directory of the +<a class="ulink" href="https://polygene.apache.org/download.html" target="_top">Polygene⢠SDK sources</a>. You should start your favorite editor and find the code related to +this tutorial, run it and play with it.</p></div><p>In this section you will find a comprehensive set of tutorials about Composite Oriented Programming using Polygeneâ¢.</p><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="tutorials-intro"></a>Polygene⢠in 42 minutes</h4></div></div></div><p>This quite long introduction to Polygene⢠will start by brushing up an overview of the problems Polygene⢠solve, teach you what +Composite Oriented Programming is and guide you through the process of writing a complete Application around an adapted +Hello World example.</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"> +<a class="xref" href="two-minutes-intro.html" title="Polygene⢠in 2 minutes">Polygene⢠in 2 minutes</a> +</li><li class="listitem"> +<a class="xref" href="ten-minutes-intro.html" title="Polygene⢠in 10 minutes">Polygene⢠in 10 minutes</a> +</li><li class="listitem"> +<a class="xref" href="thirty-minutes-intro.html" title="Polygene⢠in 30 minutes">Polygene⢠in 30 minutes</a> +</li></ul></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="_getting_real_with_polygene"></a>Getting real with Polygeneâ¢</h4></div></div></div><p>Throughout this set of tutorials it will be shown how to depend on Polygene⢠in your build, how to assemble a complete +application, how to create and work with Composites and Services, how to use contextual fragments and leverage +properties.</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"> +<a class="xref" href="howto-depend-on-polygene.html" title="Depend on Polygeneâ¢">Depend on Polygeneâ¢</a> +</li><li class="listitem"> +<a class="xref" href="howto-assemble-application.html" title="Assemble an Application">Assemble an Application</a> +</li><li class="listitem"> +<a class="xref" href="tut-composites.html" title="Transient Composites Tutorial">Transient Composites Tutorial</a> +</li><li class="listitem"> +<a class="xref" href="tut-services.html" title="Services Composites Tutorial">Services Composites Tutorial</a> +</li><li class="listitem"> +<a class="xref" href="howto-contextual-fragments.html" title="Use contextual fragments">Use Contextual Fragments</a> +</li><li class="listitem"> +<a class="xref" href="howto-leverage-properties.html" title="Leverage Properties">Leverage Properties</a> +</li></ul></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="_more_tutorials"></a>More tutorials</h4></div></div></div><p>In this other set of tutorials it will be shown how to achieve tasks that frequently arise during the development of a +typical application.</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"> +<a class="xref" href="howto-create-constraint.html" title="Create a Constraint">Create a Constraint</a> +</li><li class="listitem"> +<a class="xref" href="howto-create-concern.html" title="Create a Concern">Create a Concern</a> +</li><li class="listitem"> +<a class="xref" href="howto-create-sideeffect.html" title="Create a SideEffect">Create a SideEffect</a> +</li><li class="listitem"> +<a class="xref" href="howto-create-entity.html" title="Create an Entity">Create an Entity</a> +</li><li class="listitem"> +<a class="xref" href="howto-configure-service.html" title="Configure a Service">Configure a Service</a> +</li></ul></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="_polygene_development"></a>Polygene⢠Development</h4></div></div></div><p>This last set of tutorials youâll learn how to build the Polygene⢠SDK from sources including this very documentation website +, the Polygene⢠manual, binaries and sources distributions.</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"> +<a class="xref" href="build-system.html" title="Polygene⢠Build System">Build System</a> +</li><li class="listitem"> +<a class="xref" href="community-docs.html" title="Polygene⢠Documentation">Writing Documentation</a> +</li><li class="listitem"> +<a class="xref" href="releasing-apache.html" title="Releasing Polygeneâ¢">Releasing Polygene</a> +</li></ul></div></div></div></div><footer xmlns="" xmlns:exsl="http://exslt.org/common" class="footer"><div class="container"><p class="text-muted">Copyright © 2017 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/" target="_blank">Apache License, Version 2.0</a>. + Apache Polygene, Polygene, Apache, the Apache feather logo, and the Apache Polygene project logo are + trademarks of The Apache Software Foundation. + All other marks mentioned may be trademarks or registered trademarks of their respective owners. + </p></div></footer><script xmlns="" xmlns:exsl="http://exslt.org/common" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script><script xmlns="" xmlns:exsl="http://exslt.org/common">window.jQuery || document.write('<script src="js/jquery-1.6.4.min.js"></script>')</script><script xmlns="" xmlns:exsl="http://exslt.org/common" src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script><script xmlns="" xmlns:exsl="http://exslt.org/common" src="bootstrap-3.3.7/js/bootstrap.min.js"></script><script xmlns="" xmlns:exsl="http://exslt.org/common" src="js/ie10-viewport-bug-workaround.js"></script></body></html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-website/blob/bb9c9971/content/java/2017/two-minutes-intro.html ---------------------------------------------------------------------- diff --git a/content/java/2017/two-minutes-intro.html b/content/java/2017/two-minutes-intro.html new file mode 100644 index 0000000..adaf6c0 --- /dev/null +++ b/content/java/2017/two-minutes-intro.html @@ -0,0 +1,149 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Polygene⢠in 2 minutes</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1" /><link rel="home" href="index.html" title="" /><link rel="up" href="tutorials.html" title="Tutorials" /><link rel="prev" href="tutorials.html" title="Tutorials" /><link rel="next" href="ten-minutes-intro.html" title="Polygene⢠in 10 minutes" /> + + + <meta charset="utf-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> + <meta name="description" content=""> + <meta name="author" content=""> + <link rel="icon" href="../../favicon.ico"> + + <title>Starter Template for Bootstrap</title> + + <!-- Bootstrap core CSS --> + <link href="bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet"> + + <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> + <link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet"> + + <!-- Custom styles for this template --> + <link href="css/polygene-ng.css" rel="stylesheet"> + + <!-- Just for debugging purposes. Don't actually copy these 2 lines! --> + <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]--> + <script src="js/ie-emulation-modes-warning.js"></script> + + <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> + <!--[if lt IE 9]> + <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> + <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> + <![endif]--> + +<!-- favicon --> + +<link rel="shortcut icon" href="http://polygene.apache.org/favicon.ico" type="image/vnd.microsoft.icon" /> +<link rel="icon" href="http://polygene.apache.org/favicon.ico" type="image/x-icon" /> + +<!-- style --> + +<link href="css/shCore.css" rel="stylesheet" type="text/css" /> +<link href="css/shCoreEclipse.css" rel="stylesheet" type="text/css" /> +<link href="css/shThemeEclipse.css" rel="stylesheet" type="text/css" /> +<!--<link href="css/polygene.css" rel="stylesheet" type="text/css" />--> + +<!-- Syntax Highlighter --> + +<script type="text/javascript" src="js/shCore.js"></script> +<script type="text/javascript" src="js/shBrushJava.js"></script> +<script type="text/javascript" src="js/shBrushScala.js"></script> +<script type="text/javascript" src="js/shBrushJScript.js"></script> +<script type="text/javascript" src="js/shBrushBash.js"></script> +<script type="text/javascript" src="js/shBrushPlain.js"></script> +<script type="text/javascript" src="js/shBrushXml.js"></script> +<script type="text/javascript" src="js/shBrushGroovy.js"></script> +<script type="text/javascript" src="js/shBrushPython.js"></script> +<script type="text/javascript" src="js/shBrushRuby.js"></script> +<script type="text/javascript" src="js/shBrushCSharp.js"></script> + +<script type="text/javascript"> + SyntaxHighlighter.defaults['tab-size'] = 4; + SyntaxHighlighter.defaults['gutter'] = false; + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all() +</script> + +<!-- JQuery --> + +<script type="text/javascript" src="js/jquery-1.6.4.min.js"></script> + +<!-- Image Scaler --> + +<script type="text/javascript" src="js/imagescaler.js"></script> + +<!-- Table Styler --> + +<script type="text/javascript" src="js/tablestyler.js"></script> + +<!-- Apache Polygene WebSite Progressive Enhancement --> + +<link href="css/progressive-enhancement.css" rel="stylesheet" type="text/css" /> +<script type="text/javascript" src="js/jquery.scrollTo-1.4.2.js"></script> +<script type="text/javascript" src="js/progressive-enhancement.js"></script> + +<!-- Analytics --> + <script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-62007352-1']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + </script> + + </head><body><div xmlns="" xmlns:exsl="http://exslt.org/common" class="logo"><a href="index.html"><img src="images/logo-standard.png" /></a></div><nav xmlns="" xmlns:exsl="http://exslt.org/common" class="navbar navbar-inverse navbar-fixed-top"><div class="container"><div class="navbar-header"><a class="navbar-brand" href="#">Apache<br />Polygene + </a></div><div id="navbar" class="collapse navbar-collapse"><span class="nav navbar-nav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl class="toc"><dt><span class="section"><a href="index.html#home">Polygeneâ¢</a></span></dt><dt><span class="section"><a href="intro.html">Introduction</a></span></dt><dt><span class="section"><span xmlns="" href="tutorials.html">Tutorials</span></span></dt><dt><span class="section"><a href="javadocs.html">Javadoc</a></span></dt><dt><span class="section"><a href="samples.html">Samples</a></span></dt><dt><span class="section"><a href="core.html">Core</a></span></dt><dt><span class="section"><a href="libraries.html">Libraries</a></span></dt><dt><span class="section"><a href="extensions.html">Extensions</a></span></dt><dt><span class="section"><a href="tools.html">Tools</a></span></dt><dt><span class="section"><a href="glossary.html">Glossary </a></span></dt></dl></div></span></div></div></nav><div xmlns="" xmlns:exsl="http://exslt .org/common" class="sidenav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl class="toc"><dt><span class="section"><a href="tutorials.html#_overview">Overview</a></span></dt><dt><span class="section"><span xmlns="" href="two-minutes-intro.html">Polygene⢠in 2 minutes</span></span></dt><dt><span class="section"><a href="ten-minutes-intro.html">Polygene⢠in 10 minutes</a></span></dt><dt><span class="section"><a href="thirty-minutes-intro.html">Polygene⢠in 30 minutes</a></span></dt><dt><span class="section"><a href="howto-depend-on-polygene.html">Depend on Polygeneâ¢</a></span></dt><dt><span class="section"><a href="howto-assemble-application.html">Assemble an Application</a></span></dt><dt><span class="section"><a href="tut-composites.html">Transient Composites Tutorial</a></span></dt><dt><span class="section"><a href="tut-services.html">Services Composites Tutorial</a></span></dt><dt><span class="section"><a href="howto-contextual-fragments.html">Use contextual frag ments</a></span></dt><dt><span class="section"><a href="howto-leverage-properties.html">Leverage Properties</a></span></dt><dt><span class="section"><a href="howto-create-constraint.html">Create a Constraint</a></span></dt><dt><span class="section"><a href="howto-create-concern.html">Create a Concern</a></span></dt><dt><span class="section"><a href="howto-create-sideeffect.html">Create a SideEffect</a></span></dt><dt><span class="section"><a href="howto-create-entity.html">Create an Entity</a></span></dt><dt><span class="section"><a href="howto-configure-service.html">Configure a Service</a></span></dt><dt><span class="section"><a href="howto-invocation-annotation.html">Use @Invocation</a></span></dt><dt><span class="section"><a href="build-system.html">Polygene⢠Build System</a></span></dt><dt><span class="section"><a href="community-docs.html">Polygene⢠Documentation</a></span></dt><dt><span class="section"><a href="releasing-apache.html">Releasing Polygeneâ¢</a></span></dt>< /dl></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="two-minutes-intro"></a>Polygene⢠in 2 minutes</h3></div></div></div><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Tip</h3><p>Theses tutorials are based on actual code found in the <code class="literal">tutorials/</code> directory of the +<a class="ulink" href="https://polygene.apache.org/download.html" target="_top">Polygene⢠SDK sources</a>. You should start your favorite editor and find the code related to +this tutorial, run it and play with it.</p></div><p>To show that Polygene⢠is not necessarily complex, not hard to get going with and easy to deploy, we are first showing the +classic HelloWorld, as small as it can get and still be Composite Oriented Programming and not only standard OOP.</p><p>If you want to reproduce whatâs explained in this tutorial, remember to depend on the Core Runtime artifact that depends +on Core API, Core SPI, and Core Bootstrap:</p><div class="table"><a id="idm684"></a><p class="title"><strong>Table 1. Artifact</strong></p><div class="table-contents"><table summary="Artifact" border="1"><colgroup><col class="col_1" /><col class="col_2" /><col class="col_3" /></colgroup><thead><tr><th align="left" valign="top">Group ID</th><th align="left" valign="top">Artifact ID</th><th align="left" valign="top">Version</th></tr></thead><tbody><tr><td align="left" valign="top"><p>org.apache.polygene.core</p></td><td align="left" valign="top"><p>org.apache.polygene.core.runtime</p></td><td align="left" valign="top"><p>0</p></td></tr></tbody></table></div></div><br class="table-break" /><p>See the <a class="xref" href="howto-depend-on-polygene.html" title="Depend on Polygeneâ¢">Depend on Polygeneâ¢</a> tutorial for details.</p><p>Ready, Set, Go!</p><p>Letâs say we want to do the common HelloWorld example, but with a more domain-oriented setting. +We have a Speaker interface that does the talking. +But we also need an implementation for Speaker, which we declare here via the <code class="literal">@Mixins( SpeakerMixin.class )</code>.</p><pre class="programlisting brush: java">@Mixins( SpeakerMixin.class ) +public interface Speaker +{ + String sayHello(); +} +</pre><p>And of course, the simple implementation of the Speaker interface. +In this case, return a String with the content "Hello, World!".</p><pre class="programlisting brush: java">public class SpeakerMixin + implements Speaker +{ + @Override + public String sayHello() + { + return "Hello, World!"; + } +} +</pre><p>So far so good. We now need to make this into something that can run. This can be done like this;</p><pre class="programlisting brush: java">public class Main +{ + public static void main( String[] args ) + throws Exception + { + SingletonAssembler assembler = new SingletonAssembler() // <1> + { + @Override + public void assemble( ModuleAssembly assembly ) + throws AssemblyException + { + assembly.transients( Speaker.class ); // <2> + } + }; + Speaker speaker = assembler.module().newTransient( Speaker.class ); // <3> + System.out.println( speaker.sayHello() ); + } +} +</pre><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"> +The SingletonAssembler is a convenience class that creates a Polygene⢠Runtime instance and an application with one layer + and one module in it. +</li><li class="listitem"> +We declare a TransientComposite of type <code class="literal">Speaker</code>. +</li><li class="listitem"> +We create the Composite instance from the Module. +</li></ol></div><p><span class="strong"><strong>Done!</strong></span></p><p>Next step, <a class="xref" href="ten-minutes-intro.html" title="Polygene⢠in 10 minutes">Polygene⢠in 10 minutes</a>.</p></div><footer xmlns="" xmlns:exsl="http://exslt.org/common" class="footer"><div class="container"><p class="text-muted">Copyright © 2017 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/" target="_blank">Apache License, Version 2.0</a>. + Apache Polygene, Polygene, Apache, the Apache feather logo, and the Apache Polygene project logo are + trademarks of The Apache Software Foundation. + All other marks mentioned may be trademarks or registered trademarks of their respective owners. + </p></div></footer><script xmlns="" xmlns:exsl="http://exslt.org/common" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script><script xmlns="" xmlns:exsl="http://exslt.org/common">window.jQuery || document.write('<script src="js/jquery-1.6.4.min.js"></script>')</script><script xmlns="" xmlns:exsl="http://exslt.org/common" src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script><script xmlns="" xmlns:exsl="http://exslt.org/common" src="bootstrap-3.3.7/js/bootstrap.min.js"></script><script xmlns="" xmlns:exsl="http://exslt.org/common" src="js/ie10-viewport-bug-workaround.js"></script></body></html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-website/blob/bb9c9971/content/java/2017/what-is-cop.html ---------------------------------------------------------------------- diff --git a/content/java/2017/what-is-cop.html b/content/java/2017/what-is-cop.html new file mode 100644 index 0000000..96fefd7 --- /dev/null +++ b/content/java/2017/what-is-cop.html @@ -0,0 +1,300 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>What is COP?</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1" /><link rel="home" href="index.html" title="" /><link rel="up" href="intro.html" title="Introduction" /><link rel="prev" href="introduction-background.html" title="Background" /><link rel="next" href="what-s-an-object-anyway.html" title="Whatâs an Object anyway?" /> + + + <meta charset="utf-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> + <meta name="description" content=""> + <meta name="author" content=""> + <link rel="icon" href="../../favicon.ico"> + + <title>Starter Template for Bootstrap</title> + + <!-- Bootstrap core CSS --> + <link href="bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet"> + + <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> + <link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet"> + + <!-- Custom styles for this template --> + <link href="css/polygene-ng.css" rel="stylesheet"> + + <!-- Just for debugging purposes. Don't actually copy these 2 lines! --> + <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]--> + <script src="js/ie-emulation-modes-warning.js"></script> + + <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> + <!--[if lt IE 9]> + <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> + <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> + <![endif]--> + +<!-- favicon --> + +<link rel="shortcut icon" href="http://polygene.apache.org/favicon.ico" type="image/vnd.microsoft.icon" /> +<link rel="icon" href="http://polygene.apache.org/favicon.ico" type="image/x-icon" /> + +<!-- style --> + +<link href="css/shCore.css" rel="stylesheet" type="text/css" /> +<link href="css/shCoreEclipse.css" rel="stylesheet" type="text/css" /> +<link href="css/shThemeEclipse.css" rel="stylesheet" type="text/css" /> +<!--<link href="css/polygene.css" rel="stylesheet" type="text/css" />--> + +<!-- Syntax Highlighter --> + +<script type="text/javascript" src="js/shCore.js"></script> +<script type="text/javascript" src="js/shBrushJava.js"></script> +<script type="text/javascript" src="js/shBrushScala.js"></script> +<script type="text/javascript" src="js/shBrushJScript.js"></script> +<script type="text/javascript" src="js/shBrushBash.js"></script> +<script type="text/javascript" src="js/shBrushPlain.js"></script> +<script type="text/javascript" src="js/shBrushXml.js"></script> +<script type="text/javascript" src="js/shBrushGroovy.js"></script> +<script type="text/javascript" src="js/shBrushPython.js"></script> +<script type="text/javascript" src="js/shBrushRuby.js"></script> +<script type="text/javascript" src="js/shBrushCSharp.js"></script> + +<script type="text/javascript"> + SyntaxHighlighter.defaults['tab-size'] = 4; + SyntaxHighlighter.defaults['gutter'] = false; + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all() +</script> + +<!-- JQuery --> + +<script type="text/javascript" src="js/jquery-1.6.4.min.js"></script> + +<!-- Image Scaler --> + +<script type="text/javascript" src="js/imagescaler.js"></script> + +<!-- Table Styler --> + +<script type="text/javascript" src="js/tablestyler.js"></script> + +<!-- Apache Polygene WebSite Progressive Enhancement --> + +<link href="css/progressive-enhancement.css" rel="stylesheet" type="text/css" /> +<script type="text/javascript" src="js/jquery.scrollTo-1.4.2.js"></script> +<script type="text/javascript" src="js/progressive-enhancement.js"></script> + +<!-- Analytics --> + <script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-62007352-1']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + </script> + + </head><body><div xmlns="" xmlns:exsl="http://exslt.org/common" class="logo"><a href="index.html"><img src="images/logo-standard.png" /></a></div><nav xmlns="" xmlns:exsl="http://exslt.org/common" class="navbar navbar-inverse navbar-fixed-top"><div class="container"><div class="navbar-header"><a class="navbar-brand" href="#">Apache<br />Polygene + </a></div><div id="navbar" class="collapse navbar-collapse"><span class="nav navbar-nav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl class="toc"><dt><span class="section"><a href="index.html#home">Polygeneâ¢</a></span></dt><dt><span class="section"><span xmlns="" href="intro.html">Introduction</span></span></dt><dt><span class="section"><a href="tutorials.html">Tutorials</a></span></dt><dt><span class="section"><a href="javadocs.html">Javadoc</a></span></dt><dt><span class="section"><a href="samples.html">Samples</a></span></dt><dt><span class="section"><a href="core.html">Core</a></span></dt><dt><span class="section"><a href="libraries.html">Libraries</a></span></dt><dt><span class="section"><a href="extensions.html">Extensions</a></span></dt><dt><span class="section"><a href="tools.html">Tools</a></span></dt><dt><span class="section"><a href="glossary.html">Glossary </a></span></dt></dl></div></span></div></div></nav><div xmlns="" xmlns:exsl="http://exslt .org/common" class="sidenav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl class="toc"><dt><span class="section"><a href="intro.html#highlights">Highlights</a></span></dt><dt><span class="section"><a href="tools-shell.html">Polygene Generator</a></span></dt><dt><span class="section"><a href="introduction-background.html">Background</a></span></dt><dt><span class="section"><span xmlns="" href="what-is-cop.html">What is COP?</span></span></dt><dt><span class="section"><a href="what-s-an-object-anyway.html">Whatâs an Object anyway?</a></span></dt><dt><span class="section"><a href="state-modeling.html">Polygene⢠and state modeling</a></span></dt><dt><span class="section"><a href="related.html">Related publications & projects</a></span></dt></dl></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="what-is-cop"></a>What is COP?</h3></div></div></div><p>We found this very well written blog entry on the Internet, which very well desc ribes what Composite Oriented +Programming really is.</p><p>The article uses C# and a "show by example" approach to explaining COP, and this shows clearly that COP is not +Java specific, and although Polygene⢠was (to our knowledge) first to introduce the name, it applies across languages and +potentially deserves one or more languages on its own.</p><p>The article is re-published here, as allowed by the +<a class="ulink" href="http://msdn.microsoft.com/en-us/windowsmobile/bb264332.aspx" target="_top">Microsoft Permissive License</a> +, more recently known as +<a class="ulink" href="http://www.opensource.org/licenses/MS-PL" target="_top">Microsoft Public License</a>. The content below +is NOT under the usual <a class="ulink" href="http://www.opensource.org/licenses/Apache-2.0" target="_top">Apache License</a>.</p><p>We would like to thank Fredrik Kalseth for his explicit approval as well.</p><p>Since then, this article went offline but can be found on the +<a class="ulink" href="https://web.archive.org/web/20130414005509/http://iridescence.no/post/composite-oriented-programming.aspx" target="_top">Internet Archive</a>.</p><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="_ulink_url_http_iridescence_no_post_composite_oriented_programming_aspx_composite_oriented_programming_ulink"></a><a class="ulink" href="http://iridescence.no/post/composite-oriented-programming.aspx" target="_top">Composite Oriented Programming</a></h4></div></div></div><p>Iâve written a series of post on AOP lately +(<a class="ulink" href="https://web.archive.org/web/20090417052136/http://www.iridescence.no/post/Aspect-Oriented-Programming---A-Primer.aspx" target="_top">here</a>, +<a class="ulink" href="https://web.archive.org/web/20091222150653/http://www.iridescence.no/post/Implementing-an-AOP-Framework-Part-1.aspx" target="_top">here</a> +and <a class="ulink" href="https://web.archive.org/web/20130417090819/http://www.iridescence.no/post/Implementing-an-AOP-Framework-Part-2.aspx" target="_top">here</a>), +and in the last part I promised to tackle mixins and introductions in a future post. +When I was doing my research for just that, I came cross a Java framework (just +humor me :p) called Apache Polygeneâ¢, written by Swedish Richard Ãberg, pioneering the idea of Composite +Oriented Programming, which instantly put a spell on me. Essentially, it takes the concepts from Aspect Oriented +Programming to the extreme, and for the past week Iâve dug into it with a passion. This post is the first fruits of +my labor.</p><div class="section"><div class="titlepage"><div><div><h5 class="title"><a id="_oop_is_not_object_oriented"></a>OOP is Not Object Oriented!</h5></div></div></div><p>One of the things that Richard Ãberg argues, is that OOP is not really object oriented at all, but rather class +oriented. As the Polygene⢠website proclaims, "class is the first class citizen that objects are derived from. Not objects +being the first-class citizen to which one or many classes are assigned". Composite oriented programming (COP) then, +tries to work around this limitation by building on a set of core principles; that behavior depends on context, that +decoupling is a virtue, and that business rules matter more. For a short and abstract explanation of COP, +<a class="link" href="introduction-background.html" title="Background">see this page</a>. In the rest of this post Iâll try and explain some of its easily graspable +benefits through a set of code examples, and then in a future post weâll look at how Iâve morphed the AOP framework +I started developing in the previous posts in this series into a lightweight COP framework that can actually make +it compile and run.</p></div><div class="section"><div class="titlepage"><div><div><h5 class="title"><a id="_lead_by_example"></a>Lead by Example</h5></div></div></div><p><span class="emphasis"><em>Lets pause for a short aside: obviously the examples presented here are going to be architectured beyond any rational +sense, but the interesting part lies in seeing the bigger picture; imagine the principles presented here applied on a +much larger scale and Iâm sure you can see the benefits quite clearly when we reach the end.</em></span></p><p>Imagine that we have a class Division, which knows how to divide one number by another:</p><pre class="programlisting brush: c#">public class Division +{ + public Int64 Dividend { get; set; } + private long _divisor = 1; + + public Int64 Divisor + { + get { return _divisor; } + set + { + if(value == 0) + { + throw new ArgumentException("Cannot set the divisor to 0; division by 0 is not allowed."); + } + _divisor = value; + } + } + + public Int64 Calculate() + { + Trace.WriteLine("Calculating the division of " + this.Dividend + " by " + this.Divisor); + Int64 result = this.Dividend/this.Divisor; + Trace.WriteLine("Returning result: " + result); + return result; + } +}</pre><p>Consider the code presented above. Do you like it? If youâve followed the discussion on AOP in the previous posts, +then you should immediately be able to identify that there are several aspects tangled together in the above class. +Weâve got data storage (the Dividend and Divisor properties), data validation (the argument check on the Divisor +setter), business logic (the actual calculation in the Calculate method) and diagnostics (the Trace calls), all +intertwined. To what extent is this class reusable if I wanted to implement addition, subtraction or multiplication +calculations? Not very, at least not unless we refactored it. We could make the Calculate method and the properties +virtual, and thus use inheritance to modify the logic of the calculation - and since this is a tiny example, it would +probably look OK. But again, think bigger - how would this apply to a huge API? It would easily become quite difficult +to manage as things got more and more complex.</p></div><div class="section"><div class="titlepage"><div><div><h5 class="title"><a id="_design_by_composition"></a>Design by Composition</h5></div></div></div><p>With a COP framework, we can implement each aspect as a separate object and then treat them as <span class="emphasis"><em>mixins</em></span> which blend +together into a meaningful <span class="emphasis"><em>composite</em></span>. Sounds confusing? Lets refactor the above example using an as of yet imaginary +COP framework for .NET (which Iâm currently developing and will post the source code for in a follow-up post), and +itâll all make sense (hopefully!).</p><p>Above, we identified the four different aspects in the Division class - so letâs implement each of them. First, we +have the data storage:</p><pre class="programlisting brush: c#">public interface ICalculationDataAspect // aspect contract +{ + long Number1 { get; set; } + long Number2 { get; set; } +} + +public class CalculationDataAspect : ICalculationDataAspect // aspect implementation +{ + public long Number1 { get; set; } + public long Number2 { get; set; } +}</pre><p>In this example, the data storage is super easy â we just provide a set of properties (using the C# 3.0 automatic +properties notation) that can hold the values in-memory. The second aspect we found, was the business logic â the +actual calculation:</p><pre class="programlisting brush: c#">public interface ICalculationLogicAspect +{ + long Calculate(); +} + +public class DivisionLogicAspect : ICalculationLogicAspect +{ + [AspectRef] ICalculationDataAspect _data; + + public long Calculate() + { + return _data.Number1 / _data.Number2; + } +}</pre><p>Here we follow the same structure again, by defining the aspect as an interface and providing an implementation of it. +In order to perform the calculation however, we need access to the data storage aspect so that we can read out the +numbers we should perform the calculation on. Using attributes, we can tell the COP framework that we require this +reference, and it will provide it for us at runtime using some dependency injection trickery behind the scenes. It is +important to notice that weâve now placed a <span class="emphasis"><em>constraint</em></span> on any possible composition of these aspects â the +DivisionLogicAspect now requires an ICalculationDataAspect to be present in any composition it is part of (our COP +framework will be able to validate such constraints, and tell us up front should we break any). It is still loosely +coupled however, because we only hold a constraint on the <span class="emphasis"><em>contract</em></span> of that aspect, not any specific implementation of +it. Weâll see the benefit of that distinction later.</p><p>The third aspect we have, is validation. We want to ensure that the divisor is never set to 0, because trying to divide +by zero is not a pleasant experience. Validation is a type of advice, which was introduced at length earlier in my AOP +series. Weâve seen it implemented using the IAdvice interface of my AOP framework, allowing us to dynamically hook up +to a method invocation. However, the advice weâre implementing here is specific to the data aspect, so with our COP +framework we can define it as <span class="emphasis"><em>concern</em></span> for that particular aspect, which gives us a much nicer implementation than an +AOP framework could - in particular because of its type safety. Just look at this:</p><pre class="programlisting brush: c#">public abstract class DivisionValidationConcern : ICalculationDataAspect +{ + [ConcernFor] protected ICalculationDataAspect _proceed; + + public abstract long Number1 { get; set; } + + public long Number2 + { + get { return _proceed.Number2; } + set + { + if (value == 0) + { + throw new ArgumentException("Cannot set the Divisor to 0 - division by zero not allowed."); + } + _proceed.Number2 = value; // here, we tell the framework to proceed with the call to the *real* Number2 property + } + } +}</pre><p>I just love that, itâs so friggin' elegant ;). Remember that an advice is allowed to control the actual method +invocation by telling the target when to proceed â weâre doing the exact same thing above, only instead of dealing with +a generic method invocation weâre actually using the interface of the aspect weâre advising to control the specific +invocation directly. In our validation, we validate the value passed into the Divisor setter, and if we find it valid +then we tell the target (represented by a field annotated with an attribute which tells the COP framework to inject the +reference into it for us, much like we did with aspects earlier) to proceed with the invocation; otherwise we throw an +exception. This particular concern is abstract, because we only wanted to advise a subset of the methods in the +interface. Thatâs merely a convenience offered us by the framework - under the covers it will automatically complete +our implementation of the members we left abstract.</p><p>Only one aspect remains now, and that is the logging:</p><pre class="programlisting brush: c#">public class LoggingAdvice : IAdvice +{ + public object Execute(AdviceTarget target) + { + Trace.WriteLine("Invoking method " + target.TargetInfo.Name + " on " + target.TargetInfo.DeclaringType.FullName); + + object retValue; + + try + { + retValue = target.Proceed(); + } + catch(Exception ex) + { + Trace.WriteLine("Method threw exception: " + ex.Message); + throw; + } + Trace.WriteLine("Method returned " + retValue); + return retValue; + } +}</pre><p>Weâve implement it as a regular advice, like weâve seen earlier in AOP, because it lends itself to much wider reuse +than the validation concern did.</p><p>Having defined all our aspects separately, it is now time to put them back together again into something that can +actually do something. We call this the composite, and it is defined as follows:</p><pre class="programlisting brush: c#">[Mixin(typeof(ICalculationDataAspect), typeof(CalculationDataAspect))] +[Mixin(typeof(ICalculationLogicAspect), typeof(DivisionLogicAspect))] +[Concern(typeof(DivisionValidationConcern))] +[Concern(typeof(LoggingAdvice))] +public interface IDivision : ICalculationDataAspect, ICalculationLogicAspect +{ }</pre><p>Basically, weâve just defined the implementation of an interface IDivision as a composition of the data and logic +aspects, and sprinkled it with the two concerns (the validation concern and the logging advice). We can now use it to +perform divisions:</p><pre class="programlisting brush: c#">IDivision division = Composer.Compose<IDivision>().Instantiate(); +division.Number1 = 10; +division.Number2 = 2; + +Int64 sum = division.Calculate();</pre><p>Thatâs pretty cool, no? Take a moment to just think about what doors this opens. To what extent do you think our code +is reusable <span class="emphasis"><em>now</em></span>, if we wanted to implement addition, subtraction and so forth? Thatâs right â all weâd need to do is +substitute the implementation of the calculation aspect with one that performs the required calculation instead of +division, and weâre done. Letâs do subtraction, for example:</p><pre class="programlisting brush: c#">public class SubtractionLogicAspect : ICalculationLogicAspect +{ + [AspectRef] ICalculationDataAspect _data; + + public long Calculate() + { + return _data.Number1 - _data.Number2; + } +}</pre><p>Thatâs it! The rest we can reuse as is, building a new composite:</p><pre class="programlisting brush: c#">[Mixin(typeof(ICalculationDataAspect), typeof(CalculationDataAspect))] +[Mixin(typeof(ICalculationLogicAspect), typeof(SubtractionLogicAspect))] +[Pointcut(typeof(LoggingAdvice))] +public interface ISubtraction : ICalculationDataAspect, ICalculationLogicAspect +{ }</pre><p>Notice that we just left out the validation concern in this composite, as it is no longer needed. What if we wanted +our subtraction to only ever return positive numbers? Easy! Weâll just implement an absolute number concern:</p><pre class="programlisting brush: c#">public class AbsoluteNumberConcern : ICalculationLogicAspect +{ + [ConcernFor] protected ICalculationLogicAspect _proceed; + + public long Calculate() + { + long result = _proceed.Calculate(); + + return Math.Abs(result); + } +}</pre><p>And then update the composition to include it:</p><pre class="programlisting brush: c#">[Mixin(typeof(ICalculationDataAspect), typeof(CalculationDataAspect))] +[Mixin(typeof(ICalculationLogicAspect), typeof(SubtractionLogicAspect))] +[Concern(typeof(AbsoluteNumberConcern))] +[Pointcut(typeof(LoggingAdvice))] +public interface ISubtraction : ICalculationDataAspect, ICalculationLogicAspect +{ }</pre><p>To Be Continuedâ¦</p><p>I hope this post has whet your appetite for more on this subject, as I will certainly pursue it further in future +posts. Iâve already implemented a prototype framework that supports the above examples, which builds on my +<a class="ulink" href="http://www.iridescence.no/Posts/Implementing-an-AOP-Framework-Part-2.aspx" target="_top">previously posted AOP framework</a>, and Iâll +post the source code for that soon. If you want to dig deeper right now (and donât mind +a bit of Java), then I suggest you head over to the Polygene⢠website and poke about there. +<a class="ulink" href="http://rickardoberg.wordpress.com/" target="_top">Richard Ãbergs blog</a> also provides great insight.</p></div></div></div><footer xmlns="" xmlns:exsl="http://exslt.org/common" class="footer"><div class="container"><p class="text-muted">Copyright © 2017 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/" target="_blank">Apache License, Version 2.0</a>. + Apache Polygene, Polygene, Apache, the Apache feather logo, and the Apache Polygene project logo are + trademarks of The Apache Software Foundation. + All other marks mentioned may be trademarks or registered trademarks of their respective owners. + </p></div></footer><script xmlns="" xmlns:exsl="http://exslt.org/common" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script><script xmlns="" xmlns:exsl="http://exslt.org/common">window.jQuery || document.write('<script src="js/jquery-1.6.4.min.js"></script>')</script><script xmlns="" xmlns:exsl="http://exslt.org/common" src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script><script xmlns="" xmlns:exsl="http://exslt.org/common" src="bootstrap-3.3.7/js/bootstrap.min.js"></script><script xmlns="" xmlns:exsl="http://exslt.org/common" src="js/ie10-viewport-bug-workaround.js"></script></body></html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-website/blob/bb9c9971/content/java/2017/what-s-an-object-anyway.html ---------------------------------------------------------------------- diff --git a/content/java/2017/what-s-an-object-anyway.html b/content/java/2017/what-s-an-object-anyway.html new file mode 100644 index 0000000..ed661fb --- /dev/null +++ b/content/java/2017/what-s-an-object-anyway.html @@ -0,0 +1,211 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Whatâs an Object anyway?</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1" /><link rel="home" href="index.html" title="" /><link rel="up" href="intro.html" title="Introduction" /><link rel="prev" href="what-is-cop.html" title="What is COP?" /><link rel="next" href="state-modeling.html" title="Polygene⢠and state modeling" /> + + + <meta charset="utf-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> + <meta name="description" content=""> + <meta name="author" content=""> + <link rel="icon" href="../../favicon.ico"> + + <title>Starter Template for Bootstrap</title> + + <!-- Bootstrap core CSS --> + <link href="bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet"> + + <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> + <link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet"> + + <!-- Custom styles for this template --> + <link href="css/polygene-ng.css" rel="stylesheet"> + + <!-- Just for debugging purposes. Don't actually copy these 2 lines! --> + <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]--> + <script src="js/ie-emulation-modes-warning.js"></script> + + <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> + <!--[if lt IE 9]> + <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> + <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> + <![endif]--> + +<!-- favicon --> + +<link rel="shortcut icon" href="http://polygene.apache.org/favicon.ico" type="image/vnd.microsoft.icon" /> +<link rel="icon" href="http://polygene.apache.org/favicon.ico" type="image/x-icon" /> + +<!-- style --> + +<link href="css/shCore.css" rel="stylesheet" type="text/css" /> +<link href="css/shCoreEclipse.css" rel="stylesheet" type="text/css" /> +<link href="css/shThemeEclipse.css" rel="stylesheet" type="text/css" /> +<!--<link href="css/polygene.css" rel="stylesheet" type="text/css" />--> + +<!-- Syntax Highlighter --> + +<script type="text/javascript" src="js/shCore.js"></script> +<script type="text/javascript" src="js/shBrushJava.js"></script> +<script type="text/javascript" src="js/shBrushScala.js"></script> +<script type="text/javascript" src="js/shBrushJScript.js"></script> +<script type="text/javascript" src="js/shBrushBash.js"></script> +<script type="text/javascript" src="js/shBrushPlain.js"></script> +<script type="text/javascript" src="js/shBrushXml.js"></script> +<script type="text/javascript" src="js/shBrushGroovy.js"></script> +<script type="text/javascript" src="js/shBrushPython.js"></script> +<script type="text/javascript" src="js/shBrushRuby.js"></script> +<script type="text/javascript" src="js/shBrushCSharp.js"></script> + +<script type="text/javascript"> + SyntaxHighlighter.defaults['tab-size'] = 4; + SyntaxHighlighter.defaults['gutter'] = false; + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all() +</script> + +<!-- JQuery --> + +<script type="text/javascript" src="js/jquery-1.6.4.min.js"></script> + +<!-- Image Scaler --> + +<script type="text/javascript" src="js/imagescaler.js"></script> + +<!-- Table Styler --> + +<script type="text/javascript" src="js/tablestyler.js"></script> + +<!-- Apache Polygene WebSite Progressive Enhancement --> + +<link href="css/progressive-enhancement.css" rel="stylesheet" type="text/css" /> +<script type="text/javascript" src="js/jquery.scrollTo-1.4.2.js"></script> +<script type="text/javascript" src="js/progressive-enhancement.js"></script> + +<!-- Analytics --> + <script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-62007352-1']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + </script> + + </head><body><div xmlns="" xmlns:exsl="http://exslt.org/common" class="logo"><a href="index.html"><img src="images/logo-standard.png" /></a></div><nav xmlns="" xmlns:exsl="http://exslt.org/common" class="navbar navbar-inverse navbar-fixed-top"><div class="container"><div class="navbar-header"><a class="navbar-brand" href="#">Apache<br />Polygene + </a></div><div id="navbar" class="collapse navbar-collapse"><span class="nav navbar-nav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl class="toc"><dt><span class="section"><a href="index.html#home">Polygeneâ¢</a></span></dt><dt><span class="section"><span xmlns="" href="intro.html">Introduction</span></span></dt><dt><span class="section"><a href="tutorials.html">Tutorials</a></span></dt><dt><span class="section"><a href="javadocs.html">Javadoc</a></span></dt><dt><span class="section"><a href="samples.html">Samples</a></span></dt><dt><span class="section"><a href="core.html">Core</a></span></dt><dt><span class="section"><a href="libraries.html">Libraries</a></span></dt><dt><span class="section"><a href="extensions.html">Extensions</a></span></dt><dt><span class="section"><a href="tools.html">Tools</a></span></dt><dt><span class="section"><a href="glossary.html">Glossary </a></span></dt></dl></div></span></div></div></nav><div xmlns="" xmlns:exsl="http://exslt .org/common" class="sidenav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl class="toc"><dt><span class="section"><a href="intro.html#highlights">Highlights</a></span></dt><dt><span class="section"><a href="tools-shell.html">Polygene Generator</a></span></dt><dt><span class="section"><a href="introduction-background.html">Background</a></span></dt><dt><span class="section"><a href="what-is-cop.html">What is COP?</a></span></dt><dt><span class="section"><span xmlns="" href="what-s-an-object-anyway.html">Whatâs an Object anyway?</span></span></dt><dt><span class="section"><a href="state-modeling.html">Polygene⢠and state modeling</a></span></dt><dt><span class="section"><a href="related.html">Related publications & projects</a></span></dt></dl></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="what-s-an-object-anyway"></a>Whatâs an Object anyway?</h3></div></div></div><p>In OOP the main idea is that we should model our reali ty by creating Objects. Objects have state, and they have methods. +Methods in an object are used to operate on the internal state and understands the domain that is being modeled.</p><p>By contrast, in procedural programming the focus is on algorithms, which can use several data structures to perform some +task. The focus is on what is going on, rather than the "objects" involved.</p><p>With OOP it becomes more difficult to "read" algorithms, as they are spread out in many objects that interact. With +procedural programming it becomes difficult to encapsulate and reuse functionality. Both represent extremes, neither of +which is "correct". The tendency to create anemic domain models is an indication that we have lost the algorithmic view +in OOP, and there is a need for it.</p><p>The main flaw of OOP, which COP addresses, is the answer to the fundamental question "What methods should an object +have?". In traditional OOP, which really should be called "class oriented programming", the classes tend to have a +rather narcissistic point of view. Classes are allowed to dictate what methods are in there - regardless of the +algorithms which they are part of - and algorithms then need to be aware of these classes when object instances +collaborate in an algorithm. Why? This seems like complete madness to me!! Keep in mind that if there were no +algorithms, there would be no need for methods at all!! Algorithms, then, are primary, and objects are what we use as +helper structures. In philosophical terms, if there is noone around to observe the universe, there would be no need for +the universe itself!</p><p>In COP the responsibility for defining the methods is reversed: algorithms which implement interactions between objects +get to declare what roles it needs the objects to implement, and the composites can then implement these. For each role +there will be an interface, and for each composite wanting to implement a role there will be a mixin in that composite. +This mixin can be specific for that composite implementation, or it can be generic and reused. The key point is that it +is the OBSERVER of the object, meaning, the algorithm, that gets to decide what the object should be able to do.</p><p>This is the same in real life. I donât get to decide how I communicate with you. I have to use english, and I have to +use email, and I have to send it to a specific mailing list. It is the algorithm of the interaction between us, the +Polygene⢠dev mailing list, that has set these rules, not <span class="strong"><strong>I</strong></span> as a participant in this interaction. The same should, +obviously, be the case for objects.</p><p>So, with the understanding that algorithms should define roles for collaborating objects, and objects should then +implement these in order to participate in these algorithms, it should be trivial to realize that what has passed for +OOP so far, in terms of "class oriented programming", where this role-focus of objects is difficult to achieve, if not +even impossible, is just plain wrong. I mean seriously, catastrophically, terminally wrong.</p><p><span class="strong"><strong>Let that sink in.</strong></span></p><p>The method that has been used so far to get around this has been the composite pattern, where one object has been +designated as "coordinator", which then delegates to a number of other objects in order to implement the various roles. +This "solution", which is caused by this fundamental flaw in "class oriented programming", is essentially a hack, and +causes a number of other problems, such as the "self schizophrenia" problem, whereby there is no way to tell where the +object really is. There is no "this" pointer that has any relevant meaning.</p><p>The Composite pattern, as implemented in COP and Polygeneâ¢, gets around this by simply saying that the composite, as a +whole, is an object. Tada, we now have a "this" pointer, and a coherent way to deal with the object graph as though it +was a single object. We are now able to get back to the strengths of the procedural approach, which allows the +implementer of the algorithm to define the roles needed for the algorithm. The roles can either be specific to an +algorithm, or they can be shared between a number of algorithms if there is a generic way for them to be expressed.</p><p><span class="strong"><strong>Goodness!</strong></span></p><p>The question now becomes: how can we use this insight to structure our composites, so that what is part of the +algorithm is not too tightly encoded in the composites, thereby making the algorithms more reusable, and making it less +necessary to read composite code when trying to understand algorithms. The assumption here is that we are going to write +more algorithms than composites, therefore it has to be easy to ready algorithms, and only when necessary dive down into +composite code.</p><p>When talking about Composites as Objects in Polygene⢠it is most relevant to look at Entities, since these represent physical +objects in a model, rather than algorithms or services, or other non-instance-oriented things.</p><p>If Entities should implement roles, via mixins, in order to interact with each other through algorithms, then the +majority of their behaviour should be put into those role-mixins. These are exposed publically for clients to use. +However, the state that is required to implement these roles should not be exposed publically, as they represent +implementation details that may change over time, may be different depending on role implementation, and usually has a +lot of rules regarding how it may be changed. In short, the state needs to be private to the composite.</p><p>This leads us to this typical implementation of an Entity</p><pre class="programlisting brush: java">@Mixins(SomeMixin.class) +interface MyEntity + extends Some, Other, EntityComposite +{} +</pre><p>where Some and Other are role interfaces defined by one or more algorithms. SomeMixin is the implementation of the Some +interface. There is NO interface that is defined by the author of MyEntity. Algorithms first, objects second!</p><p>The state needed for these mixins would then be put into separate interfaces, referred to by using the @This injection +in the mixins.</p><pre class="programlisting brush: java">interface SomeState +{ + Property<String> someProperty(); +} +</pre><p>These interfaces will pretty much ONLY contain state declarations. There might be some methods in there, but I canât +see right now what they would be.</p><p>In order to be able to get an overview of all the state being implemented by the Entity we introduce a "superstate" +interface:</p><pre class="programlisting brush: java">interface MyState + extends SomeState, OtherState //, ... +{} +</pre><p>This lets us see the totality of all the state that the Entity has, and can be used in the builder phase:</p><pre class="programlisting brush: java"> EntityBuilder<MyEntity> builder = uow.newEntityBuilder(MyEntity.class); + MyState state = builder.instanceFor(MyState.class); + + //... init state ... + + MyEntity instance = builder.newInstance(); + + + } + +} +</pre><p>This lets us divide our Entity into two parts: the internal state and the external roles of the domain that the object +takes part in. Due to the support for private mixins the state is not unnecessarily exposed, and the mixin support in +general allow our role-oriented approach to modeling. The role interfaces are strongly reusable, the mixins are +generally reusable, and the state interfaces are usually reusable. This minimizes the need for us to go into the mixin +code and read it. If we have read the mixin code once, and the same mixin is reused between objects, then this makes +it easier for us to understand it the next time we see it being used in another algorithm.</p><p>To summarize thus far, we have looked at why OOP so far has not worked out, why this is the case, and how COP deals +with it, and how we can implement a better solution of Entities using Polygeneâ¢. All is well!</p><p>The next step is to start using these Entities in algorithms. Algorithms are usually stateless, or at least they donât +have any state that survives the execution of the algorithm. There is input, some calculation, and then output. In +other words, our notion of services fit perfectly here!</p><p>Algorithms, then, should(/could?) be modeled using services. If an algorithm needs other algorithms to compute +something, that is, if a service needs another service to do something, we can accomplish this using dependency +injection, so that the user of the initial algorithm does not have to know about this implementation detail.</p><p>In a "Getting Things Done" domain model, with Projects and Actions, you might then have an algorithm like so for task +delegation:</p><pre class="programlisting brush: java">void delegate(TaskExecutor from, Completable completable, TaskExecutor to) +{ + to.inbox().createTask( createDelegatedTask( completable ) ); + + completable.complete(); // Delegated task is considered done + + from.inbox().createTask( createWaitingTask( completable ) ); +}</pre><p>In the above I donât know if "from" and "to" are human users or systems that automatically execute tasks. I also donât +know if Completable is an entire Project or a single Action. From the point of view of the algorithm I donât need to +know! All the algorithm cares about is that the roles it needs are fulfilled somehow. This means that I will be able to +extend my domain model later on, and have it be a part of these kinds of algorithms, without having to change my +algorithms. And as long as my composites implement the role interfaces, such as TaskExecutor and Completable, they can +participate in many different algorithms that use these as a way to interact with the domain objects.</p><p>This shows the place of services, as points of contact between objects in a domain model, or more generally, +"interactions". These will change often, and will increase in number as the system grows, so it is important that they +are easy to read, and that they are easy to participate in. With a focus on roles, rather than classes, this becomes +much easier to accomplish!</p><p>With the responsibilities of entities, as objects, and services, as algorithms, more clearly defined, the last part to +deal with is how these are put together. The services, with the methods now being role-oriented, can obviously be +applied to a wide variety of entities, but we now go from general to specific. In our software each general algorithm +is typically applied to specific objects in specific use-cases.</p><p><span class="strong"><strong>How is this done?</strong></span></p><p>This is done by implementing context objects, which pick specific objects and pass them into algorithms. This is +typically a UI-centric thing, and as such is difficult to encapsulate into a single method. With the previous example we +would need to get the three objects involved, and cast them to the specific roles we are interested in. The +"TaskExecutor from" could be the user running the application, the "Completable completable" could be the currently +selected item in a list, and "TaskExecutor to" could be a user designated from a popup dialog. These three are then +taken by the context and used to execute the "delegate" interaction, which performs all the steps necessary.</p><p>The interaction method "delegate" is testable, both with mocks of the input, and with specific instances of the various +roles. The implementations are also testable, and if the same mixin is used over and over for the implementation, then +only one set of tests is needed for each role interface.</p><p>To summarize we have in COP/Polygene⢠a way to get the best from procedural and object-oriented programming. As we have seen +the functionality falls into three categories, the entities implementing objects, the services implementing +interactions, and the user interface implementing the context. This also maps well to the ideas of ModelViewController, +which in turn maps well to the new ideas from Mr Reenskaug (inventor of MVC) called DCI: Data-Context-Interaction. As a +side-effect of this discussion we have therefore also seen how COP/Polygene⢠can be used to implement DCI, which is an +important next step in understanding objects and their interactions, the fundamentals of which (I believe) are captured +on this page.</p><p>Thatâs it. Well done if youâve read this far :-)</p><p>Comments and thoughts to <a class="ulink" href="mailto:[email protected]" target="_top">[email protected]</a> mailing list on this are highly appreciated. This is very very important +topics, and crucial to understanding/explaining why COP/Polygene⢠is so great! :-)</p></div><footer xmlns="" xmlns:exsl="http://exslt.org/common" class="footer"><div class="container"><p class="text-muted">Copyright © 2017 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/" target="_blank">Apache License, Version 2.0</a>. + Apache Polygene, Polygene, Apache, the Apache feather logo, and the Apache Polygene project logo are + trademarks of The Apache Software Foundation. + All other marks mentioned may be trademarks or registered trademarks of their respective owners. + </p></div></footer><script xmlns="" xmlns:exsl="http://exslt.org/common" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script><script xmlns="" xmlns:exsl="http://exslt.org/common">window.jQuery || document.write('<script src="js/jquery-1.6.4.min.js"></script>')</script><script xmlns="" xmlns:exsl="http://exslt.org/common" src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script><script xmlns="" xmlns:exsl="http://exslt.org/common" src="bootstrap-3.3.7/js/bootstrap.min.js"></script><script xmlns="" xmlns:exsl="http://exslt.org/common" src="js/ie10-viewport-bug-workaround.js"></script></body></html> \ No newline at end of file
