<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Comments for page &quot;Enclave Pattern&quot;</title>
		<link>http://250bpm.com/forum/t-563175/enclave-pattern</link>
		<description>Posts in the discussion thread &quot;Enclave Pattern&quot;</description>
				<copyright></copyright>
		<lastBuildDate>Sat, 01 Aug 2015 21:49:17 +0000</lastBuildDate>
		
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1894319</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1894319</link>
				<description></description>
				<pubDate>Sat, 16 Nov 2013 14:46:29 +0000</pubDate>
				<wikidot:authorName>Martin Sustrik</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Yes, it's a pretty lame solution. I've posted the article only because I've never seen this pattern in the wild. I thought it would make for interesting reading and possibly make people think of limitations inherent in existing languages.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1889354</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1889354</link>
				<description></description>
				<pubDate>Sun, 10 Nov 2013 06:10:26 +0000</pubDate>
				<wikidot:authorName>SasQ</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Problem 1 is still present in your solution, since you have to modify the class &#8216;B` every time you want to add it to another list. Not that it were something bad. But you&#8217;ve mentioned this yourself in your previous blog post as an argument against C++'s way, and directed it upon other people's attempts at solution, so you should respect your own standards here too ;-) According to this standard, this solution is still not the ideal. And making it ideal by enforcing 0 modifications to the &#8216;B` class, or even no recompilation required, could be difficult to achieve, if not impossible. Because, as you&#8217;ve said yourselves, you need to put those &#8216;prev` and `next` somewhere this way or another. And every time it would have to be a part of `B`&#8217;s objects' layout in memory, whenever this layout will change, `B` and its users would have to recompile at the very least, I guess.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1681547</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1681547</link>
				<description></description>
				<pubDate>Wed, 09 Jan 2013 05:19:54 +0000</pubDate>
				<wikidot:authorName>Martin Sustrik</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Thanks! As a long-time OO programmer I've found this pattern pretty surprising when it arrived to me. It kind of goes against the grain of the common use of the C++ language. Enjoy.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1681279</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1681279</link>
				<description></description>
				<pubDate>Tue, 08 Jan 2013 21:45:26 +0000</pubDate>
				<wikidot:authorName>Carbon Sink</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Martin: Congrats, this is a very interesting exercise. I like the 'enclave pattern' solution. I will use it for team projects. For small personal projects I will stick with the simpler C language solution and be a 'disciplined' programmer.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1576868</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1576868</link>
				<description></description>
				<pubDate>Sun, 30 Sep 2012 06:14:14 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Yes. However, if you check the implementation of offsetof macro, it does exactly the same thing as my implementation.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1576867</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1576867</link>
				<description></description>
				<pubDate>Sun, 30 Sep 2012 06:12:44 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Yes. Unless you use some genric-to-specific conversion (like get_containing_class) the container would have to know the type of the element it contains.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1576652</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1576652</link>
				<description></description>
				<pubDate>Sat, 29 Sep 2012 22:07:24 +0000</pubDate>
				<wikidot:authorName>Ambroz Bizjak</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>And of course even if you could declare that pointer-to-member template parameter, there may be no way to use it.</p> <div class="code"> <pre> <code>struct person { list&lt;person, &amp;person::all_persons_helper&gt;::helper all_persons_helper; // ?? };</code> </pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1576648</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1576648</link>
				<description></description>
				<pubDate>Sat, 29 Sep 2012 22:04:28 +0000</pubDate>
				<wikidot:authorName>Ambroz Bizjak</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>I've tried different solutions but it seems to be impossible to get away with only one list class (and no instance class). The problem is that you can't the declare a pointer-to-member as a template parameter because the helper type isn't declared yet. On the other hand, if you try to move helper outside of the list, it seems impossible to make it a friend of list.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1576643</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1576643</link>
				<description></description>
				<pubDate>Sat, 29 Sep 2012 21:52:30 +0000</pubDate>
				<wikidot:authorName>Ambroz Bizjak</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>I've come up with a version of your list which doesn't require get_containing_class(). Instead, the list itself knows what elements it contains and it links directly to them instead of helpers. For this to work it also needs to know what its helper object is within the element, and this is done using a pointer-to-member template parameter. (note: this does actually compile with g++ and run)</p> <div class="code"> <pre> <code>template &lt;class Entry&gt; class list { public: class helper { private: Entry *prev; Entry *next; friend class list&lt;Entry&gt;; }; template &lt;helper Entry::*HelperMember&gt; class instance { public: instance () { first = 0; last = 0; } void push_back (Entry *item) { (item-&gt;*HelperMember).next = 0; (item-&gt;*HelperMember).prev = last; if (last) { (last-&gt;*HelperMember).next = item; } else { first = item; } last = item; } private: Entry *first; Entry *last; }; }; struct person { list&lt;person&gt;::helper all_persons_helper; list&lt;person&gt;::helper tall_only_helper; int age; int weight; }; typedef list&lt;person&gt;::instance&lt;&amp;person::all_persons_helper&gt; PersonsList; typedef list&lt;person&gt;::instance&lt;&amp;person::tall_only_helper&gt; TallPersonsList; int main () { PersonsList persons; TallPersonsList tall_persons; person p1; person p2; persons.push_back(&amp;p1); persons.push_back(&amp;p2); tall_persons.push_back(&amp;p2); // p1.all_persons_helper.next = 0; // Doesn't compile! }</code> </pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1576626</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1576626</link>
				<description></description>
				<pubDate>Sat, 29 Sep 2012 20:58:18 +0000</pubDate>
				<wikidot:authorName>Ambroz Bizjak</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>I think this pointer conversion can actually be done in standard way (not implementation dependent) by using the standard offsetof() macro (as I've already mentioned in the previous blog post):</p> <p>#define container_of(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type, member)))</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1575623</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1575623</link>
				<description></description>
				<pubDate>Fri, 28 Sep 2012 07:44:17 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Yes. My claim was that using C++ for system-level programming (ZeroMQ) was not a very good idea. Once you get higher in the stack, C++ becomes more and more preferable. For rapid development where 100% reliability and utmost performance isn't that important it's almost perfect.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1567554</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1567554</link>
				<description></description>
				<pubDate>Tue, 18 Sep 2012 15:21:07 +0000</pubDate>
				<wikidot:authorName>jensa</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>It makes things easier for me, because I don't loose all the abstractions I want which make maintenance a lot easier. Programming against implementations is the worst you can do, independent from OO or not. And talking about maintainability, I can add a fourth list without changing anything in the source code by extending the declaration to have another node. The other approach violates many established principles, at least single responsibility, dependency inversion and open/closed principle.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1567550</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1567550</link>
				<description></description>
				<pubDate>Tue, 18 Sep 2012 15:16:41 +0000</pubDate>
				<wikidot:authorName>jensa</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>&quot;The OO in a certian way isolates the developer from actual memory layout and thus can lead to sub-optimal solutions&quot;</p> <p>IMHO getting away from the memory layout and working with abstractions is a benefit I am happily paying, if there is any. The mixin solution leads to a similar memory layout, though, and is more OO-style (with all OO-benefits), once one adds member functions instead of plain member variables to the mixin.</p> <p>And the conception &quot;low level == efficient&quot; is not necessarily true, as Stroustrup points out in his presentation (google for Day 1 Keynote - Bjarne Stroustrup: C++11 Style) when comparing std::sort with qsort. Both implement a quicksort, but std::sort has more information for optimization because it knows the types and can inline function calls. I would only resort to low-level optimizations when profiling has shown that it is a hotspot and measure afterwards.</p> <p>&quot;if you exercise full control over memory layout it leads to violations of OO paradigm.&quot;</p> <p>I would generalize this to &quot;if you exercise full control over memory layout it leads to violations of many established design principles of any design methodology&quot; because basing your design on implementations instead of abstractions is never a good idea, being it OO or not.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1567356</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1567356</link>
				<description></description>
				<pubDate>Tue, 18 Sep 2012 07:54:01 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>&quot;In a real OOP design, I am not interested in data members (and surely not in data layout)&quot;</p> <p>The above is exactly the point of the article. The OO in a certian way isolates the developer from actual memory layout and thus can lead to sub-optimal solutions. Other way round, if you exercise full control over memory layout it leads to violations of OO paradigm.</p> <p>&quot;Where do you enclose members into a critical section?&quot;</p> <p>I've added an example into the article.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1567351</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1567351</link>
				<description></description>
				<pubDate>Tue, 18 Sep 2012 07:49:51 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>IIRC the helio's implementation would require something like this when object is included in 3 lists:</p> <p>node &lt;node &lt; node &lt;person&gt; &gt; &gt;</p> <p>While theoretically possible, I am not sure how well would the implementation deal with multiple overloaded prev's and next's. Also, the declaration is extremely ugly and non-intuitive.</p> <p>All in all, using a simple non-OO hack instead and compex and confusing OO implementation should be preferable.</p> <p>Remember that OO is here to make things easier for you. So keep your mind open &#8212; if, in some particular case, OO doesn't deliver the ease-of-use and simplicity, just ignore it and use some other solution.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1567346</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1567346</link>
				<description></description>
				<pubDate>Tue, 18 Sep 2012 07:39:53 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>100% correct</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1567117</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1567117</link>
				<description></description>
				<pubDate>Mon, 17 Sep 2012 23:22:17 +0000</pubDate>
				<wikidot:authorName>Aristotle Pagaltzis</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>I am not sure enough in my grasp of C++ to know for sure myself, but it seems this requires class <tt>person</tt> to know it will be stored inside a container of class <tt>list</tt> – it makes it impossible to alternatively store a <tt>person</tt> instance in a container of a different class without declaring another enclave inside <tt>person</tt> for every possible container, i.e. the only encapsulation achieved here is data hiding. Is that right?</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1566717</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1566717</link>
				<description></description>
				<pubDate>Mon, 17 Sep 2012 12:50:11 +0000</pubDate>
				<wikidot:authorName>jensa</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Of course you never want to do that! You should always rely on interfaces and abstractions, and never on implementations such as data layout in memory. Having to use this kind of a hack would prevent me from using the hole machinery and use some other implementation for intrusive lists. Boost discusses some alternatives, and helio and I have shown another.</p> <p>PS: If you program in C++, you should use the C++-casts instead of the plain C casts.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1566710</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1566710</link>
				<description></description>
				<pubDate>Mon, 17 Sep 2012 12:43:34 +0000</pubDate>
				<wikidot:authorName>jensa</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Well, it adds the functionality to be part of a list to B, so in that way it is a mixin. Of course, you chose to implement the functionality in a way which is kind of non-oop because it does not talk about behavior or actions but about some members of a &quot;glorified struct&quot;. In a real OOP design, I am not interested in data members (and surely not in data layout), but in the interface and behavior of objects. I think you should focus less on data layout and data modelling but on interfaces and behavior of things if you want to have an object-oriented design.</p> <p>By the way, I don't understand &quot;That, however, doesn't fit well (at least mine) mental concept of objects. For example, I want the object to be &quot;atomic&quot; in the sense that if I enclose all of its members into a critical section, I won't get any data races and undefined behavior.&quot; What does it mean? Where do you enclose members into a critical section?</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1566506</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1566506</link>
				<description></description>
				<pubDate>Mon, 17 Sep 2012 05:21:57 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>You can use the following macro for example:</p> <div class="code"> <pre> <code>#define get_containing_class(ptr, type, member) \ ((type*) (((char*) ptr) - ((size_t) &amp;(((type*) 0)-&gt;member))))</code> </pre></div> <p>Usage:</p> <div class="code"> <pre> <code>person *p = get_containing_class (nodeptr, person, list1);</code> </pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1566456</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1566456</link>
				<description></description>
				<pubDate>Mon, 17 Sep 2012 04:03:29 +0000</pubDate>
				<wikidot:authorName>Gleb</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>How do plan getting reference from list::helper back to person object in your intrusive container?</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1563692</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1563692</link>
				<description></description>
				<pubDate>Thu, 13 Sep 2012 16:18:22 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Yes. That's another problem with the intrusive containers. When you retrieve an item from the list it's of type list::node*, you have to adjust the pointer to get the person* pointer. Typically, this is done by a macro:</p> <div class="code"> <pre> <code>/* Takes a pointer to a member variable and computes pointer to the structure that contains it. 'type' is type of the structure, not the member. */ #define get_containing_class(ptr, type, member) \ ((type*) (((char*) ptr) - ((size_t) &amp;(((type*) 0)-&gt;member))))</code> </pre></div> <p>The problem with doing this automatically is that offset of person* and list::node* varies. For example, imagine the person object can be contained in 3 different lists:</p> <div class="code"> <pre> <code>class person { list::node item1; list::node item2; list::node item3; };</code> </pre></div> <p>You have to convert the list::node* like this:</p> <div class="code"> <pre> <code>auto *p = get_containing_class (nodeptr, person, list1);</code> </pre></div> <p>The cast from list::node* to person* depends on which of the three lists the list::node* you are trying to cast belongs to.</p> <p>You can definitely devise some clever helpers based on templates and possibly involving pointers to members (-&gt;*). This is left as an exercise for the reader :)</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1563632</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1563632</link>
				<description></description>
				<pubDate>Thu, 13 Sep 2012 14:50:15 +0000</pubDate>
				<wikidot:authorName>Jan</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Thanks for the example. The encapsulation is really nice! But do I understand correctly that downside of this pattern when compared to an intrusive list is that the list is now not type safe? It seems that casting will be needed to retrieve a person from the list and the list of people will allow other types of objects to be added. But I guess you can avoid this problem by chanking a list and a node class to be templates parametrized with a type of stored object.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1563431</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1563431</link>
				<description></description>
				<pubDate>Thu, 13 Sep 2012 08:19:02 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>And here comes the interesting part. Imagine the list is thread-safe:</p> <div class="code"> <pre> <code>class list { public: class node { friend class ::list; private: class node *prev; class node *next; }; void push_back (node *item) { mtx.lock (); item-&gt;next = 0; item-&gt;prev = last; last = item; mtx.unlock (); } private: mutex mtx; node *first; node *last; };</code> </pre></div> <p>Note that data both in list and list::node are protected by the mutex.</p> <p>Now, imagine the you want to mess with prev or next fields from outside of the list class:</p> <div class="code"> <pre> <code>class person { public: list::node item; private: int age; int weight; void be_evil () { item.prev = 0; } };</code> </pre></div> <p>Obviosuly, this kind of thing would lead to race conditions and undefined behaviour. Luckily, the enclave pattern ensures that the code above won't compile:</p> <div class="code"> <pre> <code>error: ‘list::node* list::node::prev’ is private</code> </pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1563426</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1563426</link>
				<description></description>
				<pubDate>Thu, 13 Sep 2012 08:01:21 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>There's nothing special about the implementation. It's just a standard intrusive list. The interesting part is the accessibility of prev&amp;next fields. Anyway, here's an example:</p> <div class="code"> <pre> <code>class list { public: class node { friend class ::list; private: class node *prev; class node *next; }; void push_back (node *item) { item-&gt;next = 0; item-&gt;prev = last; last = item; } private: node *first; node *last; };</code> </pre></div> <p>And here's the usage:</p> <div class="code"> <pre> <code>class person { public: list::node item; private: int age; int weight; }; int main () { list l; person p; l.push_back (&amp;p.item); }</code> </pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1563122</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1563122</link>
				<description></description>
				<pubDate>Wed, 12 Sep 2012 20:57:54 +0000</pubDate>
				<wikidot:authorName>Jan</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>This looks interesting! Can you extend the example to show some list operations (for example how to add an element to the list)?</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1563041</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1563041</link>
				<description></description>
				<pubDate>Wed, 12 Sep 2012 18:23:27 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>I am just a C/C++ programmer and I have no experience with mixins, so please bear with me&#8230;</p> <p>Looking at the wikipedia article about mixins, it seems that mixins are bundles of functionality that you can add to your class.</p> <p>However, in the example in the article there's no functionality involved. Making C a member of B has zero impact on the functionality of B. It adds no functionality that can be used from within B and no additional functionality for the owners of objects of class B.</p> <p>What really happens is that memory for couple of member variables of unrelated class A is allocated with instance of B instead of with instance of A.</p> <p>The 'enclave' pattern redefines how boundaries of objects are perceived. In plain C++ class is just a glorified struct. It's a continuous piece of memory with some functions attached.</p> <p>That, however, doesn't fit well (at least mine) mental concept of objects. For example, I want the object to be &quot;atomic&quot; in the sense that if I enclose all of its members into a critical section, I won't get any data races and undefined behavior.</p> <p>So, in the last example in the article. 'list' class contains members 'prev', 'next', 'first' and 'last'. The latter two are standard members, both in terms of visibility and memory location. The former two have the same visibility as normal members, however, memory-wise they happen to be located elsewhere (alongside the instances of class 'person').</p> <p>I am not sure whether this kind of thing quialifies as a mixin. Wikipedia doesn't seem to suggest so.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1562875</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1562875</link>
				<description></description>
				<pubDate>Wed, 12 Sep 2012 13:14:07 +0000</pubDate>
				<wikidot:authorName>jensa</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Hi,</p> <p>my main point was that the solution you propose is another way to implement a mixin (or a trait), so I don't think it is a new pattern.</p> <p>1. I don't see a difference here to your solution. With template mixin, I need one mixin class for every list, while your solution needs a new helper class for every list. Both don't scale well, but the mixin have the advantage that I don't have to modify the person class every time. This is nice when it comes to testability and single responsibility.</p> <p>For both solutions, you need a different list type for every list the object will be contained in.</p> <p>2. Same solution as in your proposal: Make the members private and declare the list as friend of the mixin:</p> <p>class Personlist;</p> <p>template &lt;class contents, typename List&gt; class node: public contents<br /> {<br /> friend List;</p> <p>node&lt;contents, List&gt; *prev;<br /> node&lt;contents, List&gt; *next;<br /> };</p> <p>class person<br /> {<br /> int age;<br /> int weight;<br /> };</p> <p>typedef node&lt;person, Personlist&gt; person_node;</p> <p>class Personlist<br /> {<br /> public:<br /> void add(node&lt;person, Personlist&gt;&amp; n)<br /> {<br /> n.prev = &amp;last;<br /> n.next = nullptr;<br /> last.next = &amp;n;<br /> last = n;<br /> }</p> <p>private:<br /> node&lt;person, Personlist&gt; first;<br /> node&lt;person, Personlist&gt; last;<br /> };</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1562835</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1562835</link>
				<description></description>
				<pubDate>Wed, 12 Sep 2012 11:53:46 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Yup. Helio's solution is similar to the one above in that the contained class can't access the prev &amp; next members. However, there are two problems with it:</p> <p>1. How to embed the object into multiple lists?<br /> 2. How to ensure that prev &amp; next members are accessible only by list class and not by anyone holding pointer to the object.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1562782</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1562782</link>
				<description></description>
				<pubDate>Wed, 12 Sep 2012 08:26:21 +0000</pubDate>
				<wikidot:authorName>jensa</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>It seems that what you propose is a way to implement the listable functionality as a kind of mixin (or trait). This is usually done in C++ as a template class which inherits from the template parameter. If I remember correclty, user Helio has shown this as an example in the discussion of your last blog.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1562733</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1562733</link>
				<description></description>
				<pubDate>Wed, 12 Sep 2012 06:24:25 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>The article explicitly mentions the motivation: Implementing intrusive containers without breaking encapsulation.</p> <p>Nested class is used in the example, but it's used only to make it nicer. Everything would work in the same way even in C was declared as a top-level class.</p> <p>Closures deal with storing a snapshot of the environment, they don't seem to have much in common with the topic discussed here.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1562391</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1562391</link>
				<description></description>
				<pubDate>Tue, 11 Sep 2012 21:59:57 +0000</pubDate>
				<wikidot:authorName>andrew</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>ok, no builder, though i fail to see how static and hardcoded direct access any usefull.</p> <p>Take a look then on nested class and closure.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1562383</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1562383</link>
				<description></description>
				<pubDate>Tue, 11 Sep 2012 21:34:42 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>I still don't follow.</p> <p>According to wikipedia: &quot;The intent of the Builder design pattern is to separate the construction of a complex object from its representation. By doing so, the same construction process can create different representations.&quot;</p> <p>However, the construction is not being discussed here.</p> <p>What's discussed is a data member of class A, which cannot be accessed by methods of class A, only by methods of unrelated class B.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1562374</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1562374</link>
				<description></description>
				<pubDate>Tue, 11 Sep 2012 21:19:06 +0000</pubDate>
				<wikidot:authorName>andrew</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>msdn.microsoft.com /en-US/library/8b1xzat2(v=vs.100)<br /> Simple iterator pattern.<br /> Based on nested class pattern. msdn.microsoft.com /en-US/library/ms173120(v=vs.110)<br /> Nested class used extensively in java as poor man closure.<br /> Gives you access to parent class members without exposing parent class innards to the world.</p> <p>Builder pattern to return nested class or aggregate as a contract appropriately constructed with specific semantics.<br /> If you want exclusivity(?) i assume you mean here immutability of items - return nested class or ask builder to make you a contract with Enumerable(iterator) to underlying storage, which do new instance(copy) of each returned item.</p> <p>In case you refer to exclusivity in a sense of immutability of underlying storage - i.e. after generating contract not to observe changes in underlying storage (new item added for example due to laziness of Iterator will be still observed) - copy underlying storage and evaluate it eagerly.</p> <p>In case you refer to exclusivity in access semantics - that’s exactly why we want to have contract.<br /> The only purpose of builder pattern is to generate the contract with exact semantics caller requested. (access semantics, items semantics (mutability), lazy, etc)</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1562353</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1562353</link>
				<description></description>
				<pubDate>Tue, 11 Sep 2012 20:34:10 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Hm. I still don't see where a data member of one class is exclusively owned by another class, which is what the blog post was about.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1562319</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1562319</link>
				<description></description>
				<pubDate>Tue, 11 Sep 2012 19:54:02 +0000</pubDate>
				<wikidot:authorName>andrew</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>well , depends how you apply it, and common ways to apply this pattern depends on type system. For example Java vs JS build pattern application.<br /> You can apply it in a way of creating nested object or in a way of creating new aggregated instance.<br /> For languages with monomorphic type system its common to apply builder pattern to create aggregated instances.</p> <p>Otherwise common pattern is to create (using builder pattern or just simply return nested object) on request a contract for some underlying (polymorphic) data structure, without breaking encapsulation of that structure. This way you can return for specific request (in case of builder pattern) a contract - immutable, with possibly wired events to underlying storage and AP pattern to morph it functionality (and safely compose it), for example to dynamicly extend contract for new query type (this can also be hardwired into builer as well but with losses).<br /> Really its all common topics in any OOP CS.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1562301</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1562301</link>
				<description></description>
				<pubDate>Tue, 11 Sep 2012 19:26:15 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Wikipedia's description of builder pattern seems to be a completely different thing:<br /> <a href="https://en.wikipedia.org/wiki/Builder_pattern#C.2B.2B">https://en.wikipedia.org/wiki/Builder_pattern#C.2B.2B</a></p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-563175#post-1562289</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-563175/enclave-pattern#post-1562289</link>
				<description></description>
				<pubDate>Tue, 11 Sep 2012 19:10:11 +0000</pubDate>
				<wikidot:authorName>andrew</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Nested objects or builder pattern - thats a regular name fo rthis, and use extensively in OOP design, when you dont want to expose object but want still gives way to query it.<br /> In case you want also to modify (by aplying or modifying behaviour) in composoable and safe way you use Aplicative functors pattern (monoidal preferably).</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>