<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[oo-Aufteilung von Memberfunktionen]]></title><description><![CDATA[<p>Hallo zusammen,<br />
ich hab da mal eine Frage von der ich mir nicht sicher bin, ob sie in diesem Subformum richtig steht oder eher ins Forum &quot;Rund um die Programmierung&quot; gehört hätte. Da es mir eher um die konkrete Implementierung geht habe ich mich entschlossen sie hier zu plazieren.</p>
<p>Ich habe eine Klasse &quot;Quadtree&quot;, einen ADT &quot;treeNode&quot; von dem ich die Klassen &quot;rootNode&quot;, &quot;internalNode&quot; und &quot;leaveNode&quot; ableite. In all diesen Klassen gibt es z.B. die Memberfunktion &quot;findLeftNeighbour(/<em>...</em>/)&quot; deren Implementation so aussieht.</p>
<pre><code class="language-cpp">void interNode::findLeftNeighbour(const treeNode *prev, 
								  PathList &amp;path, 
								  LeaveList &amp;neighbours)
{
	// find out wether the search comes from the top or the bottom
	if (myPrevious == prev)		// search comes from the top
	{
		// check if the strating-point-level is reached (empty list)
		if (path.size() == 0)	// starting-point-level reached
		{
			// the right subelements of this element are the
			// left neighbors of the element
			GetRightData(neighbours);
		}
		else					// starting-point-level not reached
		{
			switch (*(path.begin()))
			{
			case 0:
				path.pop_front();
				myNext[1]-&gt;findLeftNeighbour(this, path, neighbours);
				break;
			case 2:
				path.pop_front();
				myNext[3]-&gt;findLeftNeighbour(this, path, neighbours);
				break;
			}
		}
	}
	else						// search comes from the bottom
	{
		// find out which path the search comes from (0, 1, 2 or 3)
		int direction = 0;
		while (myNext[direction]-&gt;GetKey() != prev-&gt;GetKey())
			direction++;

		// find out wether the left neighbour lie whithin 
		// the brothers or not and proced correctly
		switch (direction)
		{
		case 1:
			myNext[0]-&gt;findLeftNeighbour(this, path, neighbours);
			break;
		case 3:
			myNext[2]-&gt;findLeftNeighbour(this, path, neighbours);
			break;
		default:	// comming from path 0 or 2, the right neighbour is not in the brothers
			path.push_front(direction);
			myPrevious-&gt;findLeftNeighbour(this, path, neighbours);
			break;
		}
	}
}
</code></pre>
<p>Ich prüfe jedes mal ob die Funktion von einer Funktion von unten oder von oben aufgerufen wurde. Ist es nach dem OO-Ansatz besser diese Funktionen in zwei verschiedene zu zerlegen oder ist dieser Entwurf in Ordnung?</p>
<p>Wenn man sie lieber in zwei Funktionen zerlegt, gibt es für solche fälle irgenwelche Namenskonventionen (z.B. findLeftNeighbourUp(/<em>...</em>/), findLeftNeighbourDown(/<em>...</em>/))?</p>
<p>Und dann hätte ich da noch eine Frage zur Platzierung eines &quot;typedef&quot;s. Z.B. ist pathList momentan jeweils in den Klassen &quot;QuadTree&quot; und &quot;treeNode&quot; als</p>
<pre><code class="language-cpp">typedef std::list&lt;int&gt; PathList;
</code></pre>
<p>definiert. Ist es in solchen Fällen besser ein separates Header File zu erstellen in dem derartige &quot;typedef&quot;s stehen oder sollen diese tatsächlich innerhalb der Klassen stehen?</p>
<p>Z.B</p>
<pre><code class="language-cpp">class QuadTree
{
public:
    typedef std::list&lt;int&gt; pathList;
    // ... andere deklarationen und definitionen ...

privat:
    // ...
};
</code></pre>
<p>Herzlichen Dank im voraus für jede Anregung.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/149588/oo-aufteilung-von-memberfunktionen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 08:38:58 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/149588.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 07 Jun 2006 13:48:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to oo-Aufteilung von Memberfunktionen on Wed, 07 Jun 2006 13:48:01 GMT]]></title><description><![CDATA[<p>Hallo zusammen,<br />
ich hab da mal eine Frage von der ich mir nicht sicher bin, ob sie in diesem Subformum richtig steht oder eher ins Forum &quot;Rund um die Programmierung&quot; gehört hätte. Da es mir eher um die konkrete Implementierung geht habe ich mich entschlossen sie hier zu plazieren.</p>
<p>Ich habe eine Klasse &quot;Quadtree&quot;, einen ADT &quot;treeNode&quot; von dem ich die Klassen &quot;rootNode&quot;, &quot;internalNode&quot; und &quot;leaveNode&quot; ableite. In all diesen Klassen gibt es z.B. die Memberfunktion &quot;findLeftNeighbour(/<em>...</em>/)&quot; deren Implementation so aussieht.</p>
<pre><code class="language-cpp">void interNode::findLeftNeighbour(const treeNode *prev, 
								  PathList &amp;path, 
								  LeaveList &amp;neighbours)
{
	// find out wether the search comes from the top or the bottom
	if (myPrevious == prev)		// search comes from the top
	{
		// check if the strating-point-level is reached (empty list)
		if (path.size() == 0)	// starting-point-level reached
		{
			// the right subelements of this element are the
			// left neighbors of the element
			GetRightData(neighbours);
		}
		else					// starting-point-level not reached
		{
			switch (*(path.begin()))
			{
			case 0:
				path.pop_front();
				myNext[1]-&gt;findLeftNeighbour(this, path, neighbours);
				break;
			case 2:
				path.pop_front();
				myNext[3]-&gt;findLeftNeighbour(this, path, neighbours);
				break;
			}
		}
	}
	else						// search comes from the bottom
	{
		// find out which path the search comes from (0, 1, 2 or 3)
		int direction = 0;
		while (myNext[direction]-&gt;GetKey() != prev-&gt;GetKey())
			direction++;

		// find out wether the left neighbour lie whithin 
		// the brothers or not and proced correctly
		switch (direction)
		{
		case 1:
			myNext[0]-&gt;findLeftNeighbour(this, path, neighbours);
			break;
		case 3:
			myNext[2]-&gt;findLeftNeighbour(this, path, neighbours);
			break;
		default:	// comming from path 0 or 2, the right neighbour is not in the brothers
			path.push_front(direction);
			myPrevious-&gt;findLeftNeighbour(this, path, neighbours);
			break;
		}
	}
}
</code></pre>
<p>Ich prüfe jedes mal ob die Funktion von einer Funktion von unten oder von oben aufgerufen wurde. Ist es nach dem OO-Ansatz besser diese Funktionen in zwei verschiedene zu zerlegen oder ist dieser Entwurf in Ordnung?</p>
<p>Wenn man sie lieber in zwei Funktionen zerlegt, gibt es für solche fälle irgenwelche Namenskonventionen (z.B. findLeftNeighbourUp(/<em>...</em>/), findLeftNeighbourDown(/<em>...</em>/))?</p>
<p>Und dann hätte ich da noch eine Frage zur Platzierung eines &quot;typedef&quot;s. Z.B. ist pathList momentan jeweils in den Klassen &quot;QuadTree&quot; und &quot;treeNode&quot; als</p>
<pre><code class="language-cpp">typedef std::list&lt;int&gt; PathList;
</code></pre>
<p>definiert. Ist es in solchen Fällen besser ein separates Header File zu erstellen in dem derartige &quot;typedef&quot;s stehen oder sollen diese tatsächlich innerhalb der Klassen stehen?</p>
<p>Z.B</p>
<pre><code class="language-cpp">class QuadTree
{
public:
    typedef std::list&lt;int&gt; pathList;
    // ... andere deklarationen und definitionen ...

privat:
    // ...
};
</code></pre>
<p>Herzlichen Dank im voraus für jede Anregung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1073198</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1073198</guid><dc:creator><![CDATA[Knecht]]></dc:creator><pubDate>Wed, 07 Jun 2006 13:48:01 GMT</pubDate></item><item><title><![CDATA[Reply to oo-Aufteilung von Memberfunktionen on Thu, 08 Jun 2006 06:45:04 GMT]]></title><description><![CDATA[<p>Ob du die Funktion zerlegst oder nicht ist an der Stelle Jacke wie Hose.<br />
Wenn die Funktion allerdings größer wird oder du die Funktionalität an anderer Stelle nachimplementieren musst wäre es sinnvoll den Code in neue Funktionen zu packen.</p>
<p>(Ich persönlich fänds schicker, wenn die Funktion findLeftNeighbour nur einmal in der Funktion aufgerufen wird, zumal die Parameter überall gleich sind.)</p>
<p>Für die typedefs gilt das Gleiche wie für die Funktionszerlegung. Ich bevorzuge es allerdings sie innerhalb der Klasse zu definieren. Dadurch sind die Typen gleich der Klasse zugeordnet, für die sie relevant sind.<br />
Zudem würde ich den Namen des Typs vielleicht mit 'T' beginnen lassen (also TPathList). Dann sieht man schon am Bezeichner dass es sich um ein Typedef handelt und nicht um eine (statische) Variable.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1073579</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1073579</guid><dc:creator><![CDATA[Mathias]]></dc:creator><pubDate>Thu, 08 Jun 2006 06:45:04 GMT</pubDate></item><item><title><![CDATA[Reply to oo-Aufteilung von Memberfunktionen on Thu, 08 Jun 2006 07:50:26 GMT]]></title><description><![CDATA[<p>@ Mathias: Danke für die Anregungen. Da ich mich erst relativ kurz mit C++ beschäftige bin ich noch relativ unsicher. Desshalb bin ich für jeden Verbesserungsvorschlag sehr dankbar.</p>
<p>Ich hab da jetzt noch eine Frage</p>
<p>Mathias schrieb:</p>
<blockquote>
<p>(Ich persönlich fänds schicker, wenn die Funktion findLeftNeighbour nur einmal in der Funktion aufgerufen wird, zumal die Parameter überall gleich sind.)</p>
</blockquote>
<p>Wie bekomme ich das hin, dass ich findLeftNeighbour nur einmal aufrufen kann? Im Augenblick rufe ich es ja auf verschiedenen Objekten auf. Z.B</p>
<pre><code class="language-cpp">// ...
myNext[0]-&gt;findLeftNeighbour(/*...*/)
// ...
myNext[1]-&gt;findLeftNeighbour(/*...*/)
// ...
</code></pre>
<p>Wie unterscheide ich dann die &quot;Richtung&quot; in der der Quadtree weitersuchen muss?</p>
<p>Danke für alle Anregungen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1073624</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1073624</guid><dc:creator><![CDATA[Knecht]]></dc:creator><pubDate>Thu, 08 Jun 2006 07:50:26 GMT</pubDate></item><item><title><![CDATA[Reply to oo-Aufteilung von Memberfunktionen on Thu, 08 Jun 2006 08:19:49 GMT]]></title><description><![CDATA[<p>hola</p>
<p>Knecht schrieb:</p>
<blockquote>
<pre><code class="language-cpp">switch (direction)
		{
		case 1:
			myNext[0]-&gt;findLeftNeighbour(this, path, neighbours);
			break;
		case 3:
			myNext[2]-&gt;findLeftNeighbour(this, path, neighbours);
			break;
		default:	// comming from path 0 or 2, the right neighbour is not in the brothers
			path.push_front(direction);
			myPrevious-&gt;findLeftNeighbour(this, path, neighbours);
			break;
		}
</code></pre>
</blockquote>
<p>vielleicht so:</p>
<pre><code class="language-cpp">if(direction &amp; 0x1)
{
   myNext[direction - 1]-&gt;findLeftNeighbour(this, path, neighbours);
}
else
{
   path.push_front(direction);
   myPrevious-&gt;findLeftNeighbour(this, path, neighbours);
}
</code></pre>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1073643</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1073643</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Thu, 08 Jun 2006 08:19:49 GMT</pubDate></item><item><title><![CDATA[Reply to oo-Aufteilung von Memberfunktionen on Thu, 08 Jun 2006 08:44:03 GMT]]></title><description><![CDATA[<p>@ Meep Meep: Danke schön!!! Das hab ich doch tatsächlich übersehen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1073663</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1073663</guid><dc:creator><![CDATA[Knecht]]></dc:creator><pubDate>Thu, 08 Jun 2006 08:44:03 GMT</pubDate></item><item><title><![CDATA[Reply to oo-Aufteilung von Memberfunktionen on Thu, 08 Jun 2006 08:58:01 GMT]]></title><description><![CDATA[<p>[quote=&quot;Meep Meep&quot;]<br />
vielleicht so:</p>
<pre><code class="language-cpp">if(direction &amp; 0x1)
{
   myNext[direction - 1]-&gt;findLeftNeighbour(this, path, neighbours);
}
else
{
   path.push_front(direction);
   myPrevious-&gt;findLeftNeighbour(this, path, neighbours);
}
</code></pre>
<p>Na das nenne ich Trickreich, aber nicht lesbar. Besser ist:</p>
<pre><code class="language-cpp">if (direction == 1 || direction == 3)
{ ...
</code></pre>
<p>Der Code ist viel klarer. Und macht euch an solchen Stellen keine Gedanken über Performance. Unterschätzt den Optimierer nicht.</p>
<p>Tntnet</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1073677</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1073677</guid><dc:creator><![CDATA[tntnet]]></dc:creator><pubDate>Thu, 08 Jun 2006 08:58:01 GMT</pubDate></item><item><title><![CDATA[Reply to oo-Aufteilung von Memberfunktionen on Thu, 08 Jun 2006 09:52:26 GMT]]></title><description><![CDATA[<p>tntnet schrieb:</p>
<blockquote>
<p>Na das nenne ich Trickreich, aber nicht lesbar. Besser ist:</p>
<pre><code class="language-cpp">if (direction == 1 || direction == 3)
{ ...
</code></pre>
<p>Der Code ist viel klarer.</p>
</blockquote>
<p>Bin im Augenblick auch bei der Variante gelandet, da ich gescheitert bin auszuknobeln wie es für</p>
<pre><code class="language-cpp">if (direction == 0 || direction == 2)
// ...
</code></pre>
<p>funktioniert. (2 und 3 hab ich noch hingekrigt, &quot;direction &amp; 0x2&quot; stimmts?)</p>
<p>Jedenfalls, danke nochmals.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1073714</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1073714</guid><dc:creator><![CDATA[Knecht]]></dc:creator><pubDate>Thu, 08 Jun 2006 09:52:26 GMT</pubDate></item></channel></rss>