<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Il Blog di Daniela Remogna alias ~FiMiEtTa~</title>
	<atom:link href="http://www.fimietta.it/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://www.fimietta.it/blog</link>
	<description></description>
	<lastBuildDate>Wed, 01 Feb 2012 09:20:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Gli Active Record di Yii: un design pattern per rappresentare le tabelle del database in un modo orientato agli oggetti.</title>
		<link>http://www.fimietta.it/blog/gli-active-record-di-yii-un-design-pattern-per-rappresentare-le-tabelle-del-database-in-un-modo-orientato-agli-oggetti.html</link>
		<comments>http://www.fimietta.it/blog/gli-active-record-di-yii-un-design-pattern-per-rappresentare-le-tabelle-del-database-in-un-modo-orientato-agli-oggetti.html#comments</comments>
		<pubDate>Wed, 01 Feb 2012 09:16:01 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2766</guid>
		<description><![CDATA[Gli Active Record sono un design pattern per interagire con il database in un modo semplice: l&#8217;obiettivo è di evitare di scrivere delle noiosissime query SQL per le comuni operazioni CRUD (create, read, update and delete).
Gli Active Record (AR), in altri termini, sono l&#8217;implementazione delle tecnica di programmazione basata sull&#8217;Object-Relational Maping (ORM)(http://it.wikipedia.org/wiki/Object-relational_mapping).

Gli Active Record trasformano:

 [...]]]></description>
			<content:encoded><![CDATA[<p>Gli <strong>Active Record</strong> sono un design pattern <em>per interagire con il database in un modo semplice</em>: l&#8217;obiettivo è di evitare di scrivere delle noiosissime query SQL per le comuni operazioni CRUD (create, read, update and delete).</p>
<p>Gli <strong>Active Record (AR)</strong>, in altri termini, sono l&#8217;implementazione delle tecnica di programmazione basata sull&#8217;<strong>Object-Relational Maping</strong> (ORM)(<a href="http://it.wikipedia.org/wiki/Object-relational_mapping" target="_blank">http://it.wikipedia.org/wiki/Object-relational_mapping</a>).</p>
<div id="attachment_2814" class="wp-caption alignleft" style="width: 600px"><a href="http://www.fimietta.it/blog/wp-content/uploads/2012/02/database-orm.jpg"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/02/database-orm.jpg" alt="database-orm" title="database-orm" width="590" height="245" class="size-full wp-image-2814" /></a><p class="wp-caption-text">database-orm</p></div>
<p><span id="more-2766"></span></p>
<p>Gli <strong>Active Record</strong> trasformano:</p>
<ul>
<li> le tabelle in classi</li>
<li>le righe in oggetti ed i campi in attributi</li>
</ul>
<p>Secondo quest&#8217;ottica, le comuni operazioni CRUD sono implementate tramite <strong>dei metodi degli Active Record</strong>.</p>
<h3>Inserimento di un nuovo record</h3>
<p>Ad esempio per inserire un nuovo <strong>post</strong> nella tabella <strong>tbl_post</strong>:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$post</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> Post<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'sample post'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'post body content'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Come potete notare non è necessario scrivere la query &#8220;<strong>INSERT INTO tbl_post(&#8230;&#8230;) VALUES(&#8230;..)</strong>&#8220;, ma semplicemente si crea un oggetto <strong>$post</strong> che è un&#8217;istanza della classe Post, si impostano i valori dei campi della tabella come se fossero delle proprietà di una classe ($post->title per impostare il titolo) ed infine si inserisce il record invocando il metodo <strong>save()</strong> ( $post->save() ).</p>
<h3>Come creare gli Active Record collegati ad una tabella del database</h3>
<p>Ora supponiamo di avere una tabella con la seguente struttura:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> tbl_post <span style="color: #66cc66;">&#40;</span><br />
&nbsp; &nbsp; id <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> AUTOINCREMENT<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; title <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">128</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; content TEXT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; create_time <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><br />
<span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Per accedere ad una tabella del database secondo la logica ORM, bisogna prima definire <strong>una classe AR</strong> che estende la classe<strong> CActiveRecord</strong>.<br />
Ricordo che <strong>ciascuna classe AR</strong> rappresenta una <strong>tabella </strong>mentre <strong>un istanza</strong> della classe AR rappresenta <strong>una riga della tabella</strong>.</p>
<p>Ecco il codice minimale per implementare la classe AR per la tabella tbl_post:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> Post <span style="color: #000000; font-weight: bold;">extends</span> CActiveRecord<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> model<span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> tableName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'tbl_post'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Attenzione che per default,<strong> il nome della classe AR è la stessa del nome della tabella</strong>.<br />
Se invece sono diverse è necessario fare <strong>un ovverride</strong> del metodo <strong>tableName()</strong>.</p>
<p>I <strong>valori delle colonne di una tabella</strong> possono essere accedute<strong> come proprietà </strong>della<strong> corrispondente istanza AR</strong>.</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$post</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> Post<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'a sample post'</span><span style="color: #339933;">;</span></div></div>
<p>E&#8217; importante notare che anche se la proprietà &#8220;<strong>title</strong>&#8221; non è stata esplicitamente dichiarata all&#8217;interno della classe <strong>Post</strong>, in realtà possiamo ugualmente accederci perché &#8220;<strong>title</strong>&#8221; è una<strong> colonna </strong>della tabella <strong>tbl_post</strong> e <strong>CActiveRecord</strong> permette che <strong>title </strong>sia accessibile come proprietà con l&#8217;aiutato del metodo magico <strong>__get() del PHP</strong>. In generale, nel caso in cui si tenti di accedere ad una colonna inesistente, il sistema solleva un&#8217;eccezione.</p>
<h3>Aggiungere un nuovo record nella tabella tbl_post</h3>
<p>Questi sono i semplici passi da seguire nel caso si voglia aggiungere un nuovo record in un tabella del database:</p>
<ol>
<li>Creare <strong>una nuova istanza della classe AR</strong> corrispondente alla tabella</li>
<li>Impostare le <strong>proprietà associate alle colonne</strong> della tabella</li>
<li>Richiamare il metodo<strong> save() </strong>per completare l&#8217;inserimento</li>
</ol>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$post</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> Post<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'sample post'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'content for the sample post'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create_time</span><span style="color: #339933;">=</span><a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Si può assegnare ad un attributo un valore di tipo <strong>CDbExpression</strong> prima che il record sia salvato nel database. </p>
<p>Ad esempio per salvare &#8220;<strong>un timestamp</strong>&#8221;  ritornato dalla funzione MySQL NOW() basta scrivere il seguente codice:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$post</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> Post<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create_time</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> CDbExpression<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'NOW()'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// $post-&gt;create_time='NOW()'; will not work because</span><br />
<span style="color: #666666; font-style: italic;">// 'NOW()' will be treated as a string</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<h3>Leggere i record</h3>
<p>Per leggere <strong>i dati di una tabella</strong> possiamo utilizzare <strong>i metodi find</strong>:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// trova la prima riga che soddisfa la condizione specificata</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// trova la riga con la chiave primaria specificata</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findByPk</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$postID</span><span style="color: #339933;">,</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// trova la riga con gli attributi specificati</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findByAttributes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// trova la prima riga utilizzando lo statement sql specificato</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findBySql</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Il <strong>metodo statico model()</strong> ritorna <strong>un&#8217;istanza della classe AR</strong>  ed è <strong>obbligatorio </strong>per ciascuna classe AR.</p>
<p>Possiamo poi leggere i valori come se si accedesse ad un normale oggetto, ad esempio echo <strong>$post->title;</strong></p>
<p>Quando richiamiamo il metodo <strong>find</strong>, utilizziamo <strong>$condition</strong> e <strong>$params </strong>per specificare le <strong>condizioni della query</strong>. </p>
<p>La <strong>condizione</strong> può essere una stringa che rappresenta <strong>la clausola WHERE di uno statement SQL</strong> mentre <strong>$params</strong> è un array di parametri i cui valori possono essere <em>abbinati ai segnaposti</em> impostati nella <strong>$condition</strong>: </p>
<p>Per esempio:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// cerca la riga con postID=10</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'postID=:postID'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':postID'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>E&#8217; possibile specificare delle query più complesse utilizzando in realtà come <strong>$condition</strong> un&#8217;istanza della classe <strong>CDbCriteria</strong>.</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$criteria</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> CDbCriteria<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$criteria</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">// only select the 'title' column</span><br />
<span style="color: #000088;">$criteria</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">condition</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'postID=:postID'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$criteria</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #339933;">=</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':postID'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$criteria</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// $params is not needed</span></div></div>
<p>Un metodo alternativo a <strong>CDbCriteria</strong> è di<em> passare un array </em>al metodo <strong>find</strong>.<br />
Come mostrato qui di seguito:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'select'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'condition'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'postID=:postID'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'params'</span><span style="color: #339933;">=&gt;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':postID'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Quando una <strong>query</strong> restituisce più di un record, possiamo usare il <strong>metodo findAll</strong>:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// find all rows satisfying the specified condition</span><br />
<span style="color: #000088;">$posts</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// find all rows with the specified primary keys</span><br />
<span style="color: #000088;">$posts</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAllByPk</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$postIDs</span><span style="color: #339933;">,</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// find all rows with the specified attribute values</span><br />
<span style="color: #000088;">$posts</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAllByAttributes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// find all rows using the specified SQL statement</span><br />
<span style="color: #000088;">$posts</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAllBySql</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Se la <strong>findAll</strong> non trova nessun record che soddisfa le condizioni specificate restituisce <strong>un array vuoto</strong>.</p>
<p>Inoltre sono forniti questi metodi:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// get the number of rows satisfying the specified condition</span><br />
<span style="color: #000088;">$n</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// get the number of rows using the specified SQL statement</span><br />
<span style="color: #000088;">$n</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">countBySql</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// check if there is at least a row satisfying the specified condition</span><br />
<span style="color: #000088;">$exists</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<h3>Aggiornamento di Record</h3>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findByPk</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'new post title'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// save the change to database</span></div></div>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// update the rows matching the specified condition</span><br />
Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">updateAll</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// update the rows matching the specified condition and primary key(s)</span><br />
Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">updateByPk</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pk</span><span style="color: #339933;">,</span><span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// update counter columns in the rows satisfying the specified conditions</span><br />
Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">updateCounters</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$counters</span><span style="color: #339933;">,</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<h3>Cancellare un Record</h3>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findByPk</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// assuming there is a post whose ID is 10</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// delete the row from the database table</span></div></div>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// delete the rows matching the specified condition</span><br />
Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deleteAll</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// delete the rows matching the specified condition and primary key(s)</span><br />
Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deleteByPk</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pk</span><span style="color: #339933;">,</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<h3>Validazione dei dati</h3>
<p>Spesso e volentieri capita che nel momento in cui desideriamo inserire o aggiornare un record del database, abbiamo bisogno di controllare se il valore della colonna è conforme a delle regole specifiche.</p>
<p><strong>AR</strong> assolve alla <strong>validazione dei dati automaticamente</strong> quando il <strong>metodo save() </strong>è invocato.<br />
La validazione è basata su regole specificate <strong>nel metodo rules() </strong>della <strong>classe AR</strong>.</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// data is valid and is successfully inserted/updated</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #b1b100;">else</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// data is invalid. call getErrors() to retrieve error messages</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Quando i dati da inserire o aggiornare sono inoltrati dal<strong> metodo post</strong> di un form, possiamo assegnarli alle rispettive <strong>proprietà della classe AR</strong> in questo modo:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Infine se desideriamo aggiornare più proprietà contemporaneamente in un colpo solo:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// assume $_POST['Post'] is an array of column values indexed by column names</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Post'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<h3>Risorse</h3>
<p>La fonte di questo articolo è <a href="http://www.yiiframework.com/doc/guide/1.1/it/database.arr" target="_blank">http://www.yiiframework.com/doc/guide/1.1/it/database.arr</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/gli-active-record-di-yii-un-design-pattern-per-rappresentare-le-tabelle-del-database-in-un-modo-orientato-agli-oggetti.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Come creare un pulsante dinamicamente in Objective-c &#8211; Iphone SDK</title>
		<link>http://www.fimietta.it/blog/come-creare-un-pulsante-dinamicamente-in-objective-c-iphone-sdk.html</link>
		<comments>http://www.fimietta.it/blog/come-creare-un-pulsante-dinamicamente-in-objective-c-iphone-sdk.html#comments</comments>
		<pubDate>Tue, 24 Jan 2012 22:15:31 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[Objective C]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2798</guid>
		<description><![CDATA[Questa porzione di codice scritta in linguaggio Objective-c, crea dinamicamente un pulsante  di larghezza 150 ed altezza 30 e lo posiziona alle coordinate (80.0, 170.0).
Il pulsante avrà come label &#8220;My Custom Button&#8221;&#8221;

Il pulsante dovrà essere in grado di rispondere agli eventi di pressione per far ciò utilizzeremo un metodo della classe  UIControl, classe [...]]]></description>
			<content:encoded><![CDATA[<p>Questa porzione di codice scritta in linguaggio Objective-c, crea dinamicamente <strong>un pulsante</strong>  di larghezza 150 ed altezza 30 e lo posiziona alle <strong>coordinate (80.0, 170.0)</strong>.<br />
Il pulsante avrà come label <strong>&#8220;My Custom Button&#8221;</strong>&#8221;</p>
<p><span id="more-2798"></span></p>
<p>Il pulsante dovrà essere in grado di rispondere agli eventi di pressione per far ciò utilizzeremo un metodo della classe  <strong>UIControl</strong>, classe da cui deriva anche <strong>UIButton</strong>.<br />
Il metodo è</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">addTarget<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>target action<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>selector<span style="color: #002200;">&#41;</span>anAction forControlEvents<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIControlEventsType<span style="color: #002200;">&#41;</span>type</div></div>
<p>L&#8217;evento che in genere ci interessa intercettare in un bottone è generalmente <strong>UIControlEventTouchUpInside</strong>.</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">UIButton <span style="color: #002200;">*</span>button <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIButton buttonWithType<span style="color: #002200;">:</span>UIButtonTypeRoundedRect<span style="color: #002200;">&#93;</span>;<br />
button.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">80.0</span>, <span style="color: #2400d9;">170</span>, <span style="color: #2400d9;">150.0</span>, <span style="color: #2400d9;">30.0</span><span style="color: #002200;">&#41;</span>;<br />
<span style="color: #002200;">&#91;</span>button setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;My Custom Button&quot;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>button addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>myButtonHandler<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>self.view addSubview<span style="color: #002200;">:</span>button<span style="color: #002200;">&#93;</span>;<br />
<br />
<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>myButtonHandler<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;new button clicked!!!&quot;</span><span style="color: #002200;">&#41;</span>;<br />
<span style="color: #002200;">&#125;</span></div></div>
<p>Ecco il risultato finale:</p>
<div id="attachment_2803" class="wp-caption alignleft" style="width: 210px"><a href="http://www.fimietta.it/blog/wp-content/uploads/2012/01/creare-dinamicamente-un-pulsante-in-objectivec1.png"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/01/creare-dinamicamente-un-pulsante-in-objectivec1.png" alt="creare-dinamicamente-un-pulsante-in-objectivec" title="creare-dinamicamente-un-pulsante-in-objectivec" width="200" height="391" class="size-full wp-image-2803" /></a><p class="wp-caption-text">creare-dinamicamente-un-pulsante-in-objectivec</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/come-creare-un-pulsante-dinamicamente-in-objective-c-iphone-sdk.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Actionscript 3 versus Objective-C: vediamo le principali differenze a livello di sintassi del codice</title>
		<link>http://www.fimietta.it/blog/actionscript-3-versus-objective-c-vediamo-le-principali-differenze-a-livello-di-sintassi-del-codice.html</link>
		<comments>http://www.fimietta.it/blog/actionscript-3-versus-objective-c-vediamo-le-principali-differenze-a-livello-di-sintassi-del-codice.html#comments</comments>
		<pubDate>Mon, 23 Jan 2012 21:05:15 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Objective C]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2784</guid>
		<description><![CDATA[Richiamare un metodo in AS3 / inviare un messaggio ad un oggetto in Objective C 
mySound.setVolume&#40;&#41;;
&#91;mySound setVolume&#93;;

Memorizzare un valore ritornato da un metodo in AS3 / Objective C
volume = mySound.getVolume&#40;&#41;;
volume = &#91;mySound getVolume&#93;;
Passaggio di un parametro ad un metodo in AS3 / Objective C
mySound.setVolume&#40;value&#41;;
&#91;mySound setVolume:value&#93;;
Passaggio di più parametri ad un metodo in AS3 / Objective [...]]]></description>
			<content:encoded><![CDATA[<h3>Richiamare un metodo in AS3 / inviare un messaggio ad un oggetto in Objective C </h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mySound.<span style="color: #0066CC;">setVolume</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">&#91;</span>mySound setVolume<span style="color: #002200;">&#93;</span>;</div></div>
<p><span id="more-2784"></span></p>
<h3>Memorizzare un valore ritornato da un metodo in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">volume = mySound.<span style="color: #0066CC;">getVolume</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">volume <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>mySound getVolume<span style="color: #002200;">&#93;</span>;</div></div>
<h3>Passaggio di un parametro ad un metodo in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mySound.<span style="color: #0066CC;">setVolume</span><span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">&#91;</span>mySound setVolume<span style="color: #002200;">:</span>value<span style="color: #002200;">&#93;</span>;</div></div>
<h3>Passaggio di più parametri ad un metodo in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mySound.<span style="color: #006600;">setLeftAndRightPan</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">left</span>, <span style="color: #0066CC;">right</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">&#91;</span>mySound setLeftAndRightPan<span style="color: #002200;">:</span>left, rightValue<span style="color: #002200;">:</span>right<span style="color: #002200;">&#93;</span></div></div>
<h3>Definizione di un metodo in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> setLeftAndRightPan<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">left</span>:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>, <span style="color: #0066CC;">right</span>:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setLeftAndRightPan<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>left, right<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>rightValue</div></div>
<h3>Variabili in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;<br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a><span style="color: #002200;">*</span> name <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #a61390;">string</span><span style="color: #002200;">&#93;</span>;</div></div>
<h3>Inizializzare una stringa in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> someString:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;foo&quot;</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span> someString <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;foo&quot;</span>;</div></div>
<h3>Concatenare due stringhe in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> firstString:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;foo&quot;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> secondString:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;bar&quot;</span>;<br />
firstString = firstString + secondString;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>firstString <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;foo&quot;</span>;<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>secondString <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bar&quot;</span>;<br />
firstString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>firstString stringByAppendingString<span style="color: #002200;">:</span>secondString<span style="color: #002200;">&#93;</span>;</div></div>
<h3>Variabile intera in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> counter:<span style="color: #0066CC;">int</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">NSInteger counter;</div></div>
<h3>Object Variable in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> vo:DataVO;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DataVO <span style="color: #002200;">*</span>vo;</div></div>
<h3>Gestione delle memoria per classi complesse in AS3 / Objective c</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> destroy<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>timer<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; timer.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span>, onTick<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; timer.<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; timer = <span style="color: #000000; font-weight: bold;">null</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>icon<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; icon.<span style="color: #006600;">bitmapData</span>.<span style="color: #006600;">dispose</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>dealloc<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #002200;">&#91;</span>timer release<span style="color: #002200;">&#93;</span><br />
&nbsp; &nbsp;<span style="color: #002200;">&#91;</span>icon release<span style="color: #002200;">&#93;</span><br />
&nbsp; &nbsp;<span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span><br />
<span style="color: #002200;">&#125;</span></div></div>
<h3>Lavorare con i MovieClip</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">//Actionscript 3</span><br />
<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> i : <span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span> ; i <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">10</span> ; i ++ <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">var</span> rect : Rectangle = <span style="color: #000000; font-weight: bold;">new</span> Rectangle<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Custom object</span><br />
&nbsp; &nbsp; &nbsp;rect.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">50</span><span style="color: #66cc66;">*</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">floor</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">%</span>4<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;rect.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">90</span><span style="color: #66cc66;">*</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">floor</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;addChild<span style="color: #66cc66;">&#40;</span>rect<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>numChildren<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//result: 10</span></div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; <span style="color: #2400d9;">10</span> ; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;Rectangle <span style="color: #002200;">*</span>rect <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Rectangle alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">40</span>,<span style="color: #2400d9;">80</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//Custom Object</span><br />
&nbsp; &nbsp; &nbsp;rect.transform <span style="color: #002200;">=</span> CGAffineTransformMakeTranslation<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">50</span><span style="color: #002200;">*</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/floor.html"><span style="color: #a61390;">floor</span></a><span style="color: #002200;">&#40;</span>i<span style="color: #002200;">%</span>4<span style="color: #002200;">&#41;</span>, <span style="color: #2400d9;">90</span><span style="color: #002200;">*</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/floor.html"><span style="color: #a61390;">floor</span></a><span style="color: #002200;">&#40;</span>i<span style="color: #002200;">/</span><span style="color: #2400d9;">4</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;<span style="color: #002200;">&#91;</span>window addSubview<span style="color: #002200;">:</span>rect<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//See that your window variable is accessible</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #002200;">&#91;</span>rect release<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%i&quot;</span>,<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>window subviews<span style="color: #002200;">&#93;</span> count<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">//result: 10</span></div></div>
<h3>Array in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> arr:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">10</span>, <span style="color: #cc66cc;">20</span>, <span style="color: #cc66cc;">30</span>, <span style="color: #cc66cc;">40</span>, <span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#93;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> num:<span style="color: #0066CC;">int</span> = arr<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span style="color: #400080;">NSArray</span></a> <span style="color: #002200;">*</span>arr <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span style="color: #400080;">NSArray</span></a> arrayWithObjects<span style="color: #002200;">:</span><span style="color: #2400d9;">10</span>, <span style="color: #2400d9;">20</span>, <span style="color: #2400d9;">30</span>, <span style="color: #2400d9;">40</span>, <span style="color: #2400d9;">50</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;<br />
NSInteger num <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>arr objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span>;</div></div>
<h3>Loop su Array in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> obj:<span style="color: #66cc66;">*</span> <span style="color: #b1b100;">in</span> arr<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// do something with obj</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/"><span style="color: #400080;">NSObject</span></a> <span style="color: #002200;">*</span>obj <span style="color: #a61390;">in</span> arr<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// do something with obj</span><br />
<span style="color: #002200;">&#125;</span></div></div>
<h3>Array Mutable in Objective C</h3>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/"><span style="color: #400080;">NSMutableArray</span></a> <span style="color: #002200;">*</span>marr <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/"><span style="color: #400080;">NSMutableArray</span></a> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>marr addObject<span style="color: #002200;">:</span><span style="color: #2400d9;">10</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>marr addObject<span style="color: #002200;">:</span><span style="color: #2400d9;">20</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>marr addObject<span style="color: #002200;">:</span><span style="color: #2400d9;">30</span><span style="color: #002200;">&#93;</span>;<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span style="color: #400080;">NSArray</span></a> <span style="color: #002200;">*</span>arr <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span style="color: #400080;">NSArray</span></a> arrayWithArray<span style="color: #002200;">:</span>marr<span style="color: #002200;">&#93;</span>;</div></div>
<h3>Array Associativi in Objective C</h3>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/"><span style="color: #400080;">NSMutableDictionary</span></a> <span style="color: #002200;">*</span>mdictionary <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/"><span style="color: #400080;">NSMutableDictionary</span></a> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>dictionary setObject<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Number of effs I give on this example&quot;</span><span style="color: #002200;">&#93;</span>;<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/"><span style="color: #400080;">NSDictionary</span></a> <span style="color: #002200;">*</span>dictionary <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/"><span style="color: #400080;">NSDictionary</span></a> dictionaryWithDictionary<span style="color: #002200;">:</span>mdictionary<span style="color: #002200;">&#93;</span>;</div></div>
<h3>Casting in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> someObject:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> castedAsString:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span>someObject<span style="color: #66cc66;">&#41;</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/"><span style="color: #400080;">NSObject</span></a> <span style="color: #002200;">*</span>someObject <span style="color: #002200;">=</span> <span style="color: #11740a; font-style: italic;">//pretend I know how to say new();</span><br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>castedAsString <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>someObject;</div></div>
<h3>Primitive in AS3/Objective C</h3>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">AS3 &nbsp; &nbsp; Objective<span style="color: #002200;">-</span>C<br />
<span style="color: #a61390;">true</span>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">YES</span><br />
<span style="color: #a61390;">false</span> &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">NO</span><br />
null&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">nil</span><br />
this&nbsp; &nbsp; &nbsp; &nbsp; self</div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/actionscript-3-versus-objective-c-vediamo-le-principali-differenze-a-livello-di-sintassi-del-codice.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firewall: IP Tables un esempio su Linux</title>
		<link>http://www.fimietta.it/blog/firewall.html</link>
		<comments>http://www.fimietta.it/blog/firewall.html#comments</comments>
		<pubDate>Wed, 11 Jan 2012 00:02:37 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[Sicurezza dei Sistemi Informatici]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2132</guid>
		<description><![CDATA[Un firewall (dall&#8217;inglese muro anticendio) è necessario perché le reti sono contigue l&#8217;una all&#8217;altra tramite dispositivi di rete router o switch. Se una rete viene attaccata, dobbiamo trovare un meccanismo che ci permetta di impedire che tale l&#8217;attacco si propaghi anche nella altre reti.
Il punto dove si posiziona un firewall non è tra internet e [...]]]></description>
			<content:encoded><![CDATA[<p>Un<strong> firewall</strong> (dall&#8217;inglese muro anticendio) è necessario perché le reti sono contigue l&#8217;una all&#8217;altra tramite dispositivi di rete <strong>router o switch</strong>. Se una rete viene attaccata, dobbiamo trovare un meccanismo che ci permetta di impedire che tale l&#8217;attacco si propaghi anche nella altre reti.</p>
<p>Il <strong>punto</strong> dove si posiziona un firewall non è tra internet e la vostra rete (questo è uno dei possibili punti) ma in termini più generali si posiziona tra due reti <strong>con due livelli di sicurezza differenti</strong>.</p>
<p>La rete con maggior sicurezza viene chiamata &#8220;<strong>rete interna</strong>&#8221; mentre quella con minor livello di sicurezza &#8220;<strong>rete esterna</strong>&#8220;.</p>
<p>Quindi un firewall si posiziona in tutti i punti in cui ci siano <strong>due livelli di sicurezza</strong> differenti.</p>
<p>Attenzione che un firewall ci protegge solo dove è chiuso, dove è aperto non ci protegge per niente.</p>
<p><span id="more-2132"></span></p>
<h3>Ingress vs Egress Firewall</h3>
<p>Un firewall controlla una comunicazione di tipo bidirezionale. Spesso si distingue la funzionalità di &#8220;<strong>ingress</strong>&#8221; ed &#8220;<strong>egress</strong>&#8221; firewall.</p>
<p>L&#8217;<strong>ingress firewall</strong> gestisce i <strong>collegamenti &#8220;incoming&#8221;</strong> (attenzione collegamenti non pacchetti) &#8211; è il tipico caso che si verifica quando dall&#8217;esterno vogliano comunicare con la nostra macchina. Ad esempio, aprire un canale TCP verso il mio server WEB è INGRESS.</p>
<p>Nell&#8217;<strong>egress firewall</strong> si gestiscono i collegamenti &#8220;outgoing&#8221; e si controlla l&#8217;attività del personale.<br />
Questa per le aziende, è un attività importante perché è anche responsabile civile l&#8217;amministratore delegato dell&#8217;azienda stessa.</p>
<p>La distinzione tra INGRESS / EGRESS firewall è molto semplice per tutti quei servizi orientati ai client. In tutte le applicazioni basati su TCP (connection oriented), chi inizia il collegamento è colui che manda il pacchetto SYN. Se invece si utilizza un protocollo connectionless come UDP, determinare la direzione del collegamento non è banale. Inoltre, siccome UDP non è affidabile, non è detto che cisano tutti i datagrammi e risulta molto più complicato determinare il termine della comunicazione.</p>
<h3>I tre comandamenti del firewall (D.Cheswick e S.Bellowin)</h3>
<ol>
<li>Il FIREWALL deve essere l&#8217;unico punto di contatto della rete interna con quella esterna</li>
<li>Solo il traffico autorizzato può attraversare il FIREWALL</li>
<li>Il FIREWALL deve essere un sistema altamente sicuro esso stesso</li>
</ol>
<p>Il primo &#8220;comandamento&#8221; ci indica che il firewall deve essere l&#8217;unico punto di contatto tra la rete interna ed esterna. Si pensi al caso in cui i dipendenti usano le chiavette per collegarsi ad internet per navigare su siti come Facebook. Questo per il gestore della sicurezza aziendale è un vero incubo perché quel traffico non è protetto da firewall e quindi potenzialmente attaccabile dai &#8220;cattivi&#8221;. Un altro caso comune, è collegarsi a una rete wifi vicina che non è protetta per navigare su internet.</p>
<p>Il secondo &#8220;comandamento&#8221; ci dice che solo il traffico autorizzato può attraversare il FIREWALL &#8211; ma cosa vuol dire esattamente &#8220;autorizzato&#8221; ? Non è semplice definirlo.</p>
<p>Il terzo comandamento dice che il firewall deve essere un sistema altamente sicuro esso stesso,nel senso che DEVE avere SOLO quel compito. Su un firewall non bisogna mettere su altri software che non è quello di sicurezza, perché se quel software ha un baco, l&#8217;attaccante entra nel FIREWALL stesso.<br />
I componenti del firewall devono essere elementi dedicati e sicuri.</p>
<h3>L&#8217;indicie della sicurezza</h3>
<p>Più aumenta la sicurezza e meno abbiamo la funzionalità.<br />
Più aumenta la funzionalità meno abbiamo la sicurezza.</p>
<h3>Politiche di autorizzazione</h3>
<p>Esistono due politiche di autorizzazione:</p>
<ol>
<li>Tutto ciò che non è espressamente permesso è vietato</li>
<li>Tutto ciò che non è espressamente vietato è permesso</li>
</ol>
<p>Nella prima si ha maggior sicurezza ma è più difficile da gestire.<br />
Nella seconda si ha minor sicurezza (porte aperte) ma è più facile da gestire.</p>
<p>Tra le due, la migliore è la prima: questa cosa è permessa e tutto il resto è vietato. Se non ci serve una porta, perché aprirla? Potrebbe essere fonte di problema.</p>
<h3>Considerazioni sui Firewall</h3>
<p>In generale è consigliabile creare un sistema semplice applicando la regola KISS (Keep It Simple Stupid) poiché più un sistema è complicato più è difficile da verificare.</p>
<p>Ad esempio, l&#8217;inventore di DJBDNS ha usato la regola KISS applicandola anche alle librerie. Nel momento in cui ad esempio in c utilizziamo la funzione strcopy, in realtà includiamo la string.h (ma tutte le altre funzione della string.h non ci servono!!!). Questa è una buona regola di programmazione sicura.</p>
<p>Un software contiene certamente dei bachi. Se il programma viene mandato in esecuzione, diventa un processo e di conseguenza un problema di sicurzza.<br />
Sul firewall bisogna far girare i processi essenziali. Questo è un lavoro molto importante difficile da applicare su sistemi operativi come Windows poiché è complicato capire cosa fanno i processi.<br />
Per questo motivo i firewall si fanno con Linux.</p>
<p>Un firewall non è una macchina general purposte, quindi no software e no utenti.</p>
<p>Il principio è che ognuno è colpevole finché non si dimostra che è innocente (per le persone il principio è il contrario <img src='http://www.fimietta.it/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> )</p>
<h3>IPTABLES</h3>
<p><strong>IP Tables</strong> fornisce funzionalità di manipolazione e filtraggio di pacchetti IP. IPtables si basa sul <strong>concetto di &#8220;chain&#8221;.</strong><br />
Ma che cos&#8217;è una chain? Una <strong>chain</strong> non è altro che una <strong>lista ordinata di regole</strong> a cui è associata una <strong>politica di default</strong>.<br />
Esistono, per il filtraggio dei pacchetti, tre catene predefinite:</p>
<ul>
<li><strong>INPUT</strong>, contiene le regole che devono essere applicate <em>ai pacchetti diretti alla macchina su cui è installato IPtables</em> che si sta configurando;
</li>
<li><strong>OUTPUT</strong>, contiene le regole che devono essere applicate <em>ai pacchetti in uscita dalla macchina su cui è installato IPtables</em> che si sta configurando;
</li>
<li><strong>FORWARD</strong>, contiene le regole che devono essere applicate ai pacchetti che non provengono e non sono diretti alla macchina su cui e` installato IPtables ma che, se l’IP forwarding è abilitato, verranno inoltrati verso una specifica interfaccia.</li>
</ul>
<h3>Come configurare IPTABLES</h3>
<p><strong>IPtables </strong>può essere configurato con il comando <strong>iptables</strong> (man iptables per maggiori informazioni). Di seguito una lista dei principali comandi:</p>
<ul>
<li>l’opzione -P chain target permette di modificare la politica di autorizzazione di default della cate- na chain (INPUT, OUTPUT, FORWARD o personalizzate) impostandola al valore target </li>
<li>-A chain e -I chain permettono di aggiunge una nuova regola rispettivamente in coda e in testa alla<br />
catena chain;</li>
<li>-D chain e -R chain permettono di cancellare o sostituire una regola in chain (tramite l’ordinale, se e`<br />
noto, o tramite un indirizzo IP);</li>
<li>
-F [chain] cancella tutte le regole presenti in chain o tutte le catene, se non viene specificato il valore<br />
di chain (attenzione: la politica di default non viene pero` modificata).</li>
<li>
-N chain crea una nuova catena di nome chain;
</li>
<li>-X chain cancella la catena chain, creata dall’utente.</li>
</ul>
<p>Si mostra di seguito l’utilizzo del comando necessario a re-inizializzare tutte le catene:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables <span style="color: #660033;">-F</span></div></div>
<p>oppure solo una, quella passata come parametro (in questo caso quella di OUTPUT):</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables <span style="color: #660033;">-F</span> OUTPUT</div></div>
<p>Quando si specifica una regola di filtraggio, è necessario fare riferimento a diverse <strong>porzioni del pacchetto IP</strong>.<br />
Per questo <strong>IP Tables</strong> mette a disposizione una serie di comandi (la lista completa disponibile tramite man):</p>
<ul>
<li>-s IP source, indirizzo IP sorgente;</li>
<p>
<li>-d IP dest, indirizzo IP destinazione;</li>
<p>
<li> &#8211;sport porta, porta sorgente;</li>
<p>
<li>&#8211;dport porta, porta destinazione;</li>
<p>
<li> -i interfaccia, interfaccia di invio/ricezione del pacchetto (catena di INPUT);</li>
<p>
<li>-o interfaccia, interfaccia di invio/ricezione del pacchetto (catena di OUTPUT);</li>
<p>
<li> -p proto, protocollo (es. tcp, udp);</li>
<p>
<li>-j azione, azione da intraprendere (il target in terminologia IP Tables);</li>
<p>
<li>-y o &#8211;syn, nel caso di opzione -p tcp, identifica un pacchetto con (solo) il flag SYN abilitato;</li>
<p>
<li>&#8211;icmp-type tipo, equivalente a -p icmp, tipo specifica il tipo di pacchetto ICMP</li>
<p>
<li>-l, abilita il log del risultato della valutazione di una regola in tramite syslog in /var/log/messages</li>
</ul>
<h3>Azioni sui pacchetti</h3>
<p>Le azioni da intraprendere, in terminologia <strong>IP Tables</strong> i “<strong>target</strong>” sono i seguenti:<br />
</p>
<ul>
<li> <strong>ACCEPT</strong>, accetta il pacchetto;</li>
<li><strong>DROP</strong>, scarta il pacchetto e non invia notifica;</li>
<li> <strong>REJECT</strong>, scarta il pacchetto ma invia una notifica, sconsigliato nella maggior parte dei casi perché accelera<br />
le procedure di scanning. Di default, viene inviato un pacchetto di tipo “ICMP port unreachable”, tuttavia<br />
questo pu`o essere cambiato impostando l’opzione &#8211;reject-with;
</li>
<li> <strong>RETURN</strong>, impone l’applicazione della default action anche se non `e stata esaminata tutta la catena.</li>
</ul>
<h3>Visualizzare lo stato del Firewall</h3>
<p>Per visualizzare lo stato del firewall:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables <span style="color: #660033;">-L</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">-v</span></div></div>
<p>dove -L sta per List rules, -v per ottenere delle informazioni dettagliate mentre -n visualizza gli indirizzi ip e le porte in formato numerico senza usare un server DNS per risolvere i nomi.</p>
<h3>Esempi di configurazione IP TABLES</h3>
<p>Per bloccare un&#8217;indirizzo ip (esempio un attaccante):</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 1.2.3.4 <span style="color: #660033;">-j</span> DROP</div></div>
<p>dove 1.2.3.4 è l&#8217;indirizzo ip della macchina che vogliamo bloccare.</p>
<p>Per bloccare un dominio (es. Facebook.com):</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> www.facebook.com <span style="color: #660033;">-j</span> DROP<br />
iptables <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> facebook.com <span style="color: #660033;">-j</span> DROP</div></div>
<p>Per bloccare le richieste ICMP:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">--icmp-type</span> echo-request <span style="color: #660033;">-j</span> DROP<br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> eth1 <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">--icmp-type</span> echo-request <span style="color: #660033;">-j</span> DROP</div></div>
<p>Aprire un range di porte:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">7000</span>:<span style="color: #000000;">7010</span> <span style="color: #660033;">-j</span> ACCEPT</div></div>
<p>Aprire / Chiudere porte comuni:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:800px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Replace ACCEPT with DROP to block port:<br />
<span style="color: #666666; font-style: italic;">## open port ssh tcp port 22 ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> ACCEPT<br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## open cups (printing service) udp/tcp port 631 for LAN users ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-p</span> udp <span style="color: #660033;">-m</span> udp <span style="color: #660033;">--dport</span> <span style="color: #000000;">631</span> <span style="color: #660033;">-j</span> ACCEPT<br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">631</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## allow time sync via NTP for lan users (open udp port 123) ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--dport</span> <span style="color: #000000;">123</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## open tcp port 25 (smtp) for all ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">25</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;"># open dns server ports for all ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--dport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-j</span> ACCEPT<br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## open http/https (Apache) server port to all ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT<br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">443</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## open tcp port 110 (pop3) for all ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">110</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## open tcp port 143 (imap) for all ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">143</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## open access to Samba file server for lan users only ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">137</span> <span style="color: #660033;">-j</span> ACCEPT<br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">138</span> <span style="color: #660033;">-j</span> ACCEPT<br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">139</span> <span style="color: #660033;">-j</span> ACCEPT<br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">445</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## open access to proxy server for lan users only ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">3128</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## open access to mysql server for lan users only ##</span><br />
iptables <span style="color: #660033;">-I</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">3306</span> <span style="color: #660033;">-j</span> ACCEPT</div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/firewall.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Una piccola introduzione al framework php Yii (Yes It Is!) &#8211; installazione e creazione di una semplice applicazione web 2.0</title>
		<link>http://www.fimietta.it/blog/una-piccola-introduzione-al-framework-php-yii-installazione-e-creazione-di-una-semplice-applicazione-web-2-0.html</link>
		<comments>http://www.fimietta.it/blog/una-piccola-introduzione-al-framework-php-yii-installazione-e-creazione-di-una-semplice-applicazione-web-2-0.html#comments</comments>
		<pubDate>Tue, 10 Jan 2012 23:50:33 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2729</guid>
		<description><![CDATA[Yii è un framework open source scritto in PHP pensato per sviluppare applicazioni web 2.0.
Yii implementa il pattern architetturale MVC (MODEL VIEW CONTROLLER) che ha come obiettivo principale quello di separare la logica di business da interfaccia utente.
Secondo questo noto pattern, nel MODEL sono memorizzati i dati dell&#8217;applicazione, nel VIEW sono visualizzati gli elementi dell&#8217;interfaccia [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Yii</strong> è un framework open source scritto in PHP pensato per sviluppare applicazioni web 2.0.</p>
<p><strong>Yii</strong> implementa il <strong>pattern architetturale MVC (MODEL VIEW CONTROLLER) </strong>che ha come obiettivo principale quello di separare la <strong>logica di business</strong> da <strong>interfaccia utente</strong>.</p>
<p>Secondo questo noto pattern, nel <strong>MODEL</strong> sono memorizzati i dati dell&#8217;applicazione, nel <strong>VIEW</strong> sono visualizzati gli elementi dell&#8217;interfaccia utente ed i dati contenuti nel model mentre il <strong>CONTROLLER</strong> gestisce principalmente la comunicazione tra <strong>MODEL e VIEW</strong>.</p>
<p>In altre parole la <strong>logica applicativa</strong> è a carico del <strong>MODEL / CONTROLLER</strong> mentre l&#8217;interfaccia utente è a carico della <strong>VIEW</strong>. Questo pattern aiuta i programmatori ad avere un codice organizzato e più facile da manutenere.</p>
<p>Oltre ad implementare il <strong>design-pattern MVC</strong>, <strong>Yii</strong> ha introdotto un ulteriore <strong>front-controller</strong> chiamato <strong>Application</strong> che funge da router di tutte le richieste web. Il <strong>front-controller</strong> analizza le richieste provenienti dal browser ed estrapola alcune informazioni utili per capire a quale <strong>controller</strong> inoltrarle.</p>
<p><span id="more-2729"></span></p>
<p>In figura è riportata la struttura di una generica applicazione Yii:</p>
<table>
<tr>
<td>
<div id="attachment_2731" class="wp-caption alignleft" style="width: 410px"><a href="http://www.fimietta.it/blog/wp-content/uploads/2012/01/struttura-di-un-applicazione-yii.png"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/01/struttura-di-un-applicazione-yii.png" alt="struttura-di-un-applicazione-yii" title="struttura-di-un-applicazione-yii" width="400" height="300" class="size-full wp-image-2731" /></a><p class="wp-caption-text">struttura-di-un-applicazione-yii</p></div>
</td>
</tr>
</table>
<h3>Ciclo di vita di una richiesta WEB all&#8217;interno del framework Yii</h3>
<ol>
<li>Il browser invia una richiesta al server che ospita l&#8217;applicazione con MVC</li>
<li>Un controllore è invocato per gestire la richiesta</li>
<li>Il controllore interagisce con il modello</li>
<li>Il controllore invoca la view</li>
<li>La view renderizza i dati sottoforma di HTML e li restituisce al browser</li>
</ol>
<h3>Convenzione sull&#8217;URL</h3>
<p>Come già detto, in un&#8217;applicazione Yii le richieste proveniente dal browser sono prima elaborate da un ROUTER che analizza la richiesta per decidere a quale applicazione inoltrarla.</p>
<p>Il router prende la decisione su quale controllore invocare in base alla struttura della URL che deve seguire questa convenzione:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">http:<span style="color: #000000; font-weight: bold;">//</span>hostname<span style="color: #000000; font-weight: bold;">/</span>index.php?<span style="color: #007800;">r</span>=ControllerID<span style="color: #000000; font-weight: bold;">/</span>ActionID</div></div>
<p>Dove la variabile GET <strong>r</strong> si riferisce alla <strong>route</strong> che sarà risolta dal router di Yii nel corrispondente <strong>controllore / azione</strong>.<br />
Se l&#8217;<strong>ActionID</strong> è omesso viene chiamato quella di default e lo stesso discorso vale per <strong>ControllerID</strong>.</p>
<p>Esempio:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">http:<span style="color: #000000; font-weight: bold;">//</span>www.example.com<span style="color: #000000; font-weight: bold;">/</span>index.php?<span style="color: #007800;">r</span>=post<span style="color: #000000; font-weight: bold;">/</span>show<span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #007800;">id</span>=<span style="color: #000000;">1</span></div></div>
<p>Se avete intenzione di indicizzare il vostro sito sui motori di ricerca, una delle principali <strong>regole SEO</strong> da seguire è l&#8217;avere degli <strong>SEO Friendly URLs</strong> (esempio con questa struttura &#8211; <strong>http://hostname/ControllerID/ActionID.html</strong>). Per far cio&#8217; vi può essere di aiuto <strong><a href="http://www.yiiframework.com/doc/api/1.1/CUrlManager" target="_blank">cUrlManager</a></strong></p>
<p>Le <strong>convenzioni</strong> sono molto utilizzate all&#8217;interno di questo framework, questo perché Yii favorisce il paradigma di programmazione &#8220;<strong>conventions over configurations</strong>&#8221; (<a href="http://it.wikipedia.org/wiki/Convention_Over_Configuration " target="_blank">http://it.wikipedia.org/wiki/Convention_Over_Configuration</a>)</p>
<h3>Convenzione sulle directory</h3>
<p>Nel momento in cui si crea un&#8217;applicazione con Yii bisogna seguire delle convenzioni sui nomi delle directory (queste convenzioni posso essere modificate):</p>
<ul>
<li><strong>WebRoot/protected</strong>: questa è la <strong>cartella principale dell&#8217;applicazione</strong> che contiene tutti gli script PHP sensibili alla sicurezza ed i file dei dati.</li>
<li><strong>WebRoot/protected/runtime</strong>: contiene i file temporanei privati generati durante l&#8217;esecuzione dell&#8217;applicazione</li>
<li><strong>WebRoot/protected/extensions</strong>:contiene tutte le estensioni di terze parti.</li>
<li><strong>WebRoot/protected/modules</strong>: contiene tutti i moduli dell&#8217;applicazione</li>
<li><strong>WebRoot/protected/controllers</strong>: contiene tutti i file delle classi controller.</li>
<li><strong>WebRoot/protected/views</strong>: contiene tutti i file delle view, comprese le view dei controller, le view dei layout e le view di sistema.</li>
<li><strong>WebRoot/protected/views/ControllerID</strong>: questa cartella contiene i file delle view di una singola classe controller. </li>
<li><strong>WebRoot/protected/views/layouts</strong>: contiene tutti i file delle view dei layout. </li>
<li><strong>WebRoot/protected/views/system</strong>: contiene tutti i file delle view delle view di sistema. </li>
<li><strong>WebRoot/assets</strong>: contiene tutti i file asset pubblicati.</li>
<li><strong>WebRoot/themes</strong>: contiene vari temi che possono essere applicati all&#8217;applicazione. Ciascuna sotto cartella rappresenta un singolo tema il cui nome è il nome della sottocartella.</li>
</ul>
<h3>Installare il Framework Yii in Windows 7 con XAMPP e creare la prima applicazione demo</h3>
<ul>
<li>Scaricare Yii framework dal sito ufficiale -<a href="http://www.yiiframework.com" title="Yii Framework" target="_blank"> http://www.yiiframework.com</a></li>
<li>Scompattare l&#8217;archivio e salvare la cartella <strong>framework</strong> all&#8217;interno della root del server web, nel mio caso <strong>c:\xamplite\htdocs</strong></li>
<li>
Modificare la <strong>variabile d&#8217;ambiente</strong> di sistema <strong>PATH</strong> aggiungendo due valori: il primo è il <em>percorso del framework</em> &#8211; <em>c:\xamplite\htdocs\framework</em> mentre il secondo è il <em>percorso dell&#8217;eseguibile php</em> che nel mio caso è <strong>c:\xamplite\php</strong>:</p>
<table>
<tr>
<td>
<a href="http://www.fimietta.it/blog/wp-content/uploads/2012/01/modifica_variabile_sistema_yii.png"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/01/modifica_variabile_sistema_yii.png" alt="modifica_variabile_sistema_yii" title="modifica_variabile_sistema_yii" width="594" height="622" class="alignleft size-full wp-image-2734" />
</td>
</tr>
</table>
<p></a>
</li>
<li>aprire il prompt dei comandi e spostarsi all&#8217;interno della propria webroot, nel mio caso c:\xamplite\htdocs: ed eseguire l&#8217;<strong>utility yiic </strong>per creare una nuova applicazione demo impartendo il comando
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">yiic webapp demo</div></div>
<p>come mostrato in figura:<br />
<a href="http://www.fimietta.it/blog/wp-content/uploads/2012/01/screenshot_esecuzione_comando_yiic1.png"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/01/screenshot_esecuzione_comando_yiic1.png" alt="screenshot_esecuzione_comando_yiic" title="screenshot_esecuzione_comando_yiic" width="600" height="583" class="alignleft size-full wp-image-2738" /></a></p>
</li>
</ul>
<h3>Ecco come si presenta all&#8217;applicazione demo appena creata</h3>
<p><a href="http://www.fimietta.it/blog/wp-content/uploads/2012/01/screenshot_prima_applicazione_con_yii.png"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/01/screenshot_prima_applicazione_con_yii.png" alt="screenshot_prima_applicazione_con_yii" title="screenshot_prima_applicazione_con_yii" width="600" height="516" class="alignleft size-full wp-image-2743" /></a></p>
<p>L&#8217;applicazione appena creata dal tool <strong>yiic</strong> è composta da quattro pagine:</p>
<ol>
<li>Home &#8211; http://localhost/demo/index.php?r=<strong>site</strong>/<strong>index</strong> </li>
<li>About &#8211; http://localhost/demo/index.php?r=<strong>site</strong>/<strong>page</strong>&#038;view=about </li>
<li>Contact &#8211; http://localhost/demo/index.php?r=<strong>site</strong>/<strong>contact</strong> </li>
<li>Login &#8211; http://localhost/demo/index.php?r=<strong>site</strong>/<strong>login</strong> </li>
</ol>
<p><strong>Home</strong> richiama l&#8217;azione <strong>index</strong> contenuta nel controller <strong>site</strong>, <strong>About</strong> richiama l&#8217;azione <strong>page</strong> del controller <strong>site</strong> passando come parametro la querystring <strong>&#038;view=about</strong>, <strong>Contact</strong> richiama l&#8217;azione <strong>contact</strong> del controller <strong>site</strong> mentre <strong>Login</strong> richiama l&#8217;azione login del controller <strong>site</strong>. </p>
<p>Per maggiori dettagli sull&#8217;applicazione appena installata: <a href="http://www.yiiframework.com/doc/guide/1.1/en/quickstart.first-app" target="_blank">http://www.yiiframework.com/doc/guide/1.1/en/quickstart.first-app</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/una-piccola-introduzione-al-framework-php-yii-installazione-e-creazione-di-una-semplice-applicazione-web-2-0.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NetBeans IDE: JVM Creation Failed vediamo come risolverlo</title>
		<link>http://www.fimietta.it/blog/netbeans-ide-jvm-creation-failed-vediamo-come-risolverlo.html</link>
		<comments>http://www.fimietta.it/blog/netbeans-ide-jvm-creation-failed-vediamo-come-risolverlo.html#comments</comments>
		<pubDate>Tue, 10 Jan 2012 10:53:18 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[Utilità]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2722</guid>
		<description><![CDATA[Ho appena installato su un sistema operativo Windows 7 a 64bit l&#8217;albiente IDE NetBeans per programmare con PHP .
Fin dal primo avvio, NetBeans mi ha segnalato il seguente errore:








Per risolvere il problema bisogna modificare tramite un editor di testo come Notepad o PSPAD un file di configurazione chiamato netbeans.conf che si trova all&#8217;interno della cartella [...]]]></description>
			<content:encoded><![CDATA[<p>Ho appena installato su un sistema operativo Windows 7 a 64bit l&#8217;albiente<strong> IDE NetBeans</strong> per programmare con<strong> PHP</strong> .<br />
Fin dal primo avvio, NetBeans mi ha segnalato il seguente errore:</p>
<table>
<tr>
<td>
<div id="attachment_2723" class="wp-caption alignleft" style="width: 480px"><a href="http://www.fimietta.it/blog/wp-content/uploads/2012/01/netbeans_errore_jvm_creation_failed.png"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/01/netbeans_errore_jvm_creation_failed.png" alt="netbeans_errore_jvm_creation_failed" title="netbeans_errore_jvm_creation_failed" width="470" height="299" class="size-full wp-image-2723" /></a><p class="wp-caption-text">netbeans_errore_jvm_creation_failed</p></div>
</td>
</tr>
</table>
<p>
<span id="more-2722"></span><br />
Per risolvere il problema bisogna modificare tramite un editor di testo come Notepad o PSPAD un file di configurazione chiamato <strong>netbeans.conf</strong> che si trova all&#8217;interno della cartella <strong>etc</strong> contenuta nel direttorio di installazione del programma  (nel mio caso <em>C:\Program Files (x86)\NetBeans 7.1\etc</em>).</p>
<p>La riga incriminata è la seguente:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">netbeans_default_options</span>=<span style="color: #ff0000;">&quot;-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.zip.disableMemoryMapping=true&quot;</span></div></div>
<p>Bisogna modificarla aggiungendo questa opzione:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">-J-XX:<span style="color: #007800;">MaxPermSize</span>=128m</div></div>
<p>Quindi la riga finale diventa:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">netbeans_default_options</span>=<span style="color: #ff0000;">&quot;-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=128m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.zip.disableMemoryMapping=true&quot;</span></div></div>
<p>Salvate e buon lavoro con NetBeans <img src='http://www.fimietta.it/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/netbeans-ide-jvm-creation-failed-vediamo-come-risolverlo.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I sistemi esperti basati su regole</title>
		<link>http://www.fimietta.it/blog/i-sistemi-esperti-basati-su-regole.html</link>
		<comments>http://www.fimietta.it/blog/i-sistemi-esperti-basati-su-regole.html#comments</comments>
		<pubDate>Wed, 16 Nov 2011 15:40:43 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[Intelligenza Artificiale]]></category>
		<category><![CDATA[forward-chaining]]></category>
		<category><![CDATA[rule based system]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2690</guid>
		<description><![CDATA[Definizione di Sistema Esperto
Un sistema esperto è un software che dopo essere stato istruito in modo opportuno, è in grado di dedurre nuove informazioni a partire da un insieme di informazioni di partenza (fatti).
In un sistema esperto la competenza di un esperto umano è codificata nella cosidetta base di conoscenza (ad esempio sotto forma di [...]]]></description>
			<content:encoded><![CDATA[<h3>Definizione di Sistema Esperto</h3>
<p>Un <strong>sistema esperto</strong> è un software che dopo essere stato istruito in modo opportuno, è in grado di <strong>dedurre nuove informazioni</strong> a partire da un insieme di informazioni di partenza <strong>(fatti)</strong>.</p>
<p>In un <strong>sistema esperto</strong> la competenza di un esperto umano è codificata nella cosidetta <strong>base di conoscenza</strong> (ad esempio sotto forma di regola), aggiornabile in base all&#8217;esperienza.</p>
<p>I sistemi esperti basati su regole sono dei programmi composti da regole della forma I<strong>F condizione THEN azione</strong>. </p>
<p>Dati una serie di fatti i sistemi esperti, grazie alle regole di cui sono composti, riescono a <strong>dedurre nuovi fatti</strong>.</p>
<p><span id="more-2690"></span></p>
<h3>Perché scegliere un sistema basato su regole</h3>
<p>Le <strong>regole</strong> ci permettono di rappresentare alcuni tipi di conoscenza che sono difficili da implementare in un canonico programma procedurale.</p>
<p>Un programma “<strong>rule-based</strong>” <em>separa la conoscenza dal resto del programma</em>.</p>
<p>Questo porta il vantaggio che se si cambia la conoscenza cio&#8217; non comporta una modifica il programma procedurale.</p>
<p>Si ha così una maggiore flessibilità, in quanto si possono rinviare alcune deciosioni oppure riconsidarle senza ricostruire completamente il programma.</p>
<p>Un programma basato su regole può essere scritto in modi diversi. Alcuni linguaggi come OPS-5 sono stati studianti per questo scopo (http://free-compilers.sharnoff.org/TOOL/OPS5-1.html).</p>
<h3>Definizione di Sistema di Produzione basato su regole:</h3>
<p>Un sistema a regole di produzione (production system) è costituito da tre componenti fondamentali:</p>
<ol>
<li><strong>Base di conoscenza a regole</strong> (che prende spesso il nome di memoria a lungo termine) in cui sono contenute le regole di produzione</li>
<li><strong>Memoria di lavoro</strong> (memoria a breve termine) in cui sono contenuti i dati e in cui vengono mantenute le conclusioni raggiunte dal sistema</li>
<li><strong>Motore inferenziale</strong></li</ol>
<p>Ogni <strong>regola di produzione</strong> ha la seguente forma:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">IF <span style="color: #339933;">&lt;</span>pattern<span style="color: #339933;">&gt;</span> THEN <span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span></div></div>
<p>Le regole non sono invocate per nome, ma sono attivate in base al <strong>pattern-matching</strong>.</p>
<h3>La conoscenza</h3>
<p><strong>Fatti:</strong> informazioni che riguardano la particolare situazione</p>
<p><strong>Regole:</strong> formulano elementari meccanismi del tipo <strong>se : : : allora : : :</strong></p>
<p><img src="http://www.fimietta.it/blog/wp-content/uploads/2011/11/motore-inferenziale1.png" alt="motore-inferenziale" title="motore-inferenziale" width="435" height="354" class="alignleft size-full wp-image-2713" /></p>
<h3>Tipi di Regole</h3>
<ul>
<li>Relazioni (e.g., relazioni causali)</li>
<li>Raccomandazioni, consigli, suggerimenti</li>
<li>Direttive</li>
<li>Strategia</li>
<li>Euristica</li>
</ul>
<h4>Raccomandazioni:</h4>
<p>SE la stagione e&#8217; autunno E il cielo e&#8217; nuvoloso<br />
ALLORA consiglio di prendere l&#8217;ombrello</p>
<h4>Strategia:</h4>
<p>SE l&#8217;auto non si avvia ALLORA controlla il serbatoio il serbatoio; passo-1 completato</p>
<p>SE passo-1 completato E il serbatoio e&#8217; pieno ALLORA controlla la batteria; passo-2 completato</p>
<h4>Euristica:</h4>
<p>SE il liquido e&#8217; scuro E ha pH < 6 E ha profumo acidulo ALLORA il liquido e' aceto balsamico</p>
<h4>Relazioni:</h4>
<p>SE il serbatoio e&#8217; vuoto ALLORA l&#8217;auto non si avvia</p>
<h4>Direttive:</h4>
<p>SE l&#8217;auto non si avvia E il serbatoio e&#8217; vuoto ALLORA riempi il serbatoio</p>
<h3>Meccanismi di Inferenza</h3>
<p>Due tipi di controllo (cioe&#8217; di concatenamento delle regole):</p>
<ul>
<li><strong>Forward chaining</strong>: cerca di giungere ad una conclusione partendo dai fatti presenti all&#8217;inizio nella memoria temporanea e applicando in avanti le regole.</li>
<li><strong>Backward chaining</strong>: si procede mediante riduzione dell&#8217;obiettivo principale (goal) a sottoproblemi. Una volta individuata la tesi da dimostrare, si applicano all&#8217;indietro le regole di produzione, cercando di trovare coerenza con i dati iniziali.</li>
</ul>
<h3>ALGORITMO FORWARD CHAINING (o DATA-DRIVEN)</h3>
<p>La <strong>memoria di lavoro</strong> nella sua configurazione iniziale contiene la conoscenza iniziale sul problema, cioè i fatti noti.</p>
<p>Le regole di produzione applicabili sono quelle il cui antecedente può fare matching con la memoria di lavoro (F-rules).</p>
<p>Ogni volta che una regola viene selezionata ed eseguita nuovi fatti dimostrati vengono inseriti nella memoria di lavoro.</p>
<p>Il procedimento termina con successo quando nella<br />
memoria di lavoro viene inserito anche il goal da dimostrare (condizione di terminazione).</p>
<h4>Algoritmo Base</h4>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">while</span> <span style="color: #339933;">&lt;</span>obiettivo non raggiunto<span style="color: #339933;">&gt;</span> <span style="color: #b1b100;">do</span><br />
&nbsp; &nbsp; begin<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>MATCH<span style="color: #339933;">:</span> determina l<span style="color: #ff0000;">'insieme delle regole<br />
applicabili (cio_e le regole il cui<br />
&nbsp; &nbsp; &nbsp; &nbsp; antecedente _e soddisfatto dai fatti<br />
&nbsp; &nbsp; &nbsp; &nbsp; contenuti nella memoria di lavoro)&gt;;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;CONFLICT_RESOLUTION: seleziona la regola<br />
&nbsp; &nbsp; &nbsp; &nbsp; da applicare&gt;;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;FIRE: esegui l'</span>azione associata<br />
&nbsp; &nbsp; &nbsp; &nbsp; alla regola<span style="color: #339933;">&gt;;</span><br />
&nbsp; &nbsp; end<span style="color: #339933;">;</span></div></div>
<p>Ecco il processo di inferenza schemattizato nel seguente flow-chart:</p>
<p><img src="http://www.fimietta.it/blog/wp-content/uploads/2011/11/schema-inferenza-forward-chaining1.png" alt="schema-inferenza-forward-chaining" title="schema-inferenza-forward-chaining" width="482" height="340" class="alignleft size-full wp-image-2708" /><br />
</p>
<p><img src="http://www.fimietta.it/blog/wp-content/uploads/2011/11/barra.png" alt="i sistemi esperti basati su regole" title="i sistemi esperti basati su regole" width="550" height="16" class="alignleft size-full wp-image-2614" /></p>
<h3>Esempio Forward Chaining</h3>
<p>Regole:<br />
R1: Y and D → Z<br />
R2: X and B and E → Y<br />
R3: A → X<br />
R4: C → L<br />
R5: L and M → N<br />
Fatti: A B C D E</p>
<p>Regole applicabili: R3,R4<br />
2. Applichiamo R3 (preferenza alla regola con indice piu&#8217; basso); R3 non potra&#8217; piu&#8217; essere usata<br />
3. Fatti: A B C D E X<br />
4. Regole applicabili: R2,R4<br />
5. Applichiamo R2<br />
6. Fatti: A B C D E X Y<br />
7. Regole applicabili: R1,R4<br />
8. Applichiamo R1<br />
9. Fatti: A B C D E X Y Z<br />
10. Regole applicabili: R4<br />
11. Applichiamo R4<br />
12. Fatti: A B C D E X Y Z L<br />
13. stop</p>
<h3>Conflict resolution</h3>
<p>•	Ordine lessicografico (e.g., R3 prima di R6)<br />
•	Attirubuire valori di priorita&#8217; alle regole<br />
•	Preferire le regole piu&#8217; dettagliate (e.g., quelle con una precondizione piu&#8217; restrittiva)<br />
•	Preferire le regole inserite piu&#8217; recentemente<br />
•	Metaregole: regole che impongono un ordine sulle regole. E.g., preferire le regole espresse da esperti `piu&#8217; vecchi&#8217;</p>
<h3>Possibili Estensioni</h3>
<p>1.	Teoria dei Fattori di certezza (si asserisce una conclusione che e&#8217; vera con una certa probabilita&#8217;)<br />
2.	Ragionamento probabilistico (principalmente basato sul teorema di Bayes)<br />
3.	Regole fuzzy. E.g., SE il carico della lavatrice e&#8217; leggero ALLORA usa poca acqua</p>
<h3>Esempio:</h3>
<p>Si consideri un sistema esperto che contiene le seguenti regole:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">R1<span style="color: #009900;">&#41;</span> SE piove ALLORA erba_bagnata<br />
R2<span style="color: #009900;">&#41;</span> SE piove ALLORA tetto_bagnato<br />
R3<span style="color: #009900;">&#41;</span> SE innaffiatore_acceso ALLORA erba_bagnata<br />
R4<span style="color: #009900;">&#41;</span> SE tetto_bagnato ALLORA acqua_in_garage</div></div>
<p>E i seguenti fatti:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">F1<span style="color: #009900;">&#41;</span> piove</div></div>
<p>Applichiamo le modalità di ragionamento forward per sapere se è vero che c’è acqua in garage (cioè l’affermazione acqua_in_garage è verà).</p>
<p>Nel caso di più regole applicabili, scegliamo di applicare per prima la regola con indice più basso (cioè R2 sarà eseguita prima di R5).</p>
<h3>Forward chaining</h3>
<p>La memoria di lavoro contiene solo un’informazione: piove. </p>
<p>Cerchiamo una regola che abbia una corrispondenza (matching) con un fatto (ne abbiamo uno solo per ora). </p>
<p>Ci sono due regole applicabili: R1 e R2. Applichiamo R1 e inseriamo nella memoria di lavoro il fatto erba_bagnata. La regola R1 non sarà più considerata. </p>
<p>Cerchiamo ora altre regole applicabili: dati i fatti (piove e erba_bagnata), rimane solo R2 che ha una corrispondenza. Applichiamo R2 e aggiungiamo alla memoria di alvoro il fatto tetto_bagnato. </p>
<p>Ripetiamo il procedimento. Dati i fatti correnti e l’eliminazione delle regole <strong>R1 e R2</strong>, possiamo applicare solo la regola R4 che cio permette di inserire nella memoria di lavoro il fatto <strong>acqua_in_garage</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/i-sistemi-esperti-basati-su-regole.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I protocolli in Objective C sono molto simili alle interfacce di Java</title>
		<link>http://www.fimietta.it/blog/i-protocolli-in-objective-c-sono-molto-simili-alle-interfacce-di-java.html</link>
		<comments>http://www.fimietta.it/blog/i-protocolli-in-objective-c-sono-molto-simili-alle-interfacce-di-java.html#comments</comments>
		<pubDate>Tue, 15 Nov 2011 16:37:51 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[Objective C]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2657</guid>
		<description><![CDATA[Nel linguaggio Objective C sono presenti i protocolli.  In parole povere un protocollo è la stessa cosa di quello che in Java ed altri linguaggi come ad esempio Actionscript si chiama interfaccia.
Vediamo in termini più formali una definizione di protocollo: è un insieme di metodi che vengono dichiarati come entità a se stanti e [...]]]></description>
			<content:encoded><![CDATA[<p>Nel linguaggio <strong>Objective C</strong> sono presenti i <strong>protocolli</strong>.  In parole povere un <strong>protocollo</strong> è la stessa cosa di quello che in <strong>Java</strong> ed altri linguaggi come ad esempio Actionscript si chiama<strong> interfaccia</strong>.</p>
<p>Vediamo in termini più formali una definizione di <strong>protocollo</strong>:<em> è un insieme di metodi che vengono dichiarati come entità a se stanti e che vengono usati dalle classi per prendersi degli impegni su come devono comportarsi</em>.<br />
<span id="more-2657"></span></p>
<p><img src="http://www.fimietta.it/blog/wp-content/uploads/2011/11/barra.png" alt="i protocolli in objective c " title="i protocolli in objective c " width="550" height="16" class="alignleft size-full wp-image-2614" /></p>
<h3>Come si dichiara un protocollo</h3>
<p>Si dichiara all&#8217;interno della coppia <strong>@protocol / @end</strong>.</p>
<p>Come nel caso delle interfacce, all&#8217;interno di un <strong>protocollo</strong> sono presenti <strong>esclusivamente le signatures</strong> dei metodi.</p>
<p>La <strong>classe</strong> che <em>adotta un protocollo</em> si prenderà l&#8217;impegno di <strong>attribuire un corpo ai metodi </strong>specificati nel protocollo.</p>
<p>Se una classe adotta un determinato protocollo, anche le sue sottoclassi automaticamente lo adotteranno.</p>
<h3>Perché si usano i protocolli?</h3>
<p>Perché adottando un protocollo una classe informa i propri utilizzatori del fatto che è capace di rispondere ad un&#8217;insieme di metodi senza porre dei limiti sull&#8217;ereditarietà.</p>
<h3>Differenza rispetto a Java /AS</h3>
<p>C&#8217;è una sottile ma importante differenza. Se in Java/AS dichiariamo che una certa classe implementa un&#8217;interfaccia e poi ci dimentichiamo di mettere il codice per un metodo, il compilatore si blocca e non genera l&#8217;eseguibile. Mentre in Objective C il compilatore ci da un <strong>warning</strong>, quindi produce ugualmente un eseguibile. Se in fase di runtime chiamiamo il metodo che manca, l&#8217;applicazione inevitabilmente si bloccherà.</p>
<p>Questo impone una maggior attenzione da parte del programmatore ai messaggi di warning restituiti dal compilatore.</p>
<h3>Esempio</h3>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a61390;">@protocol</span> Print<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> print<br />
<span style="color: #a61390;">@end</span><br />
<br />
<span style="color: #a61390;">@interface</span> MyClass <span style="color: #002200;">:</span> <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/"><span style="color: #400080;">NSObject</span></a> &lt;Print&gt;<br />
<span style="color: #002200;">&#123;</span><br />
...<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> MyClass<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> print <span style="color: #002200;">&#123;</span> .... <span style="color: #002200;">&#125;</span><br />
<span style="color: #a61390;">@end</span></div></div>
<p>Nell&#8217;esempio abbiamo definito un protocollo di nome <strong>Print</strong> che contiene la signature di un metodo <strong>print</strong>.<br />
Nella parte dichiarativa di una classe (@interface) oltre a definire il nome della classe (MyClass) e la classe da cui MyClass eredita (NSObject), tra parentesi angolari indichiamo che MyClass adotta il protocollo Print.</p>
<p>Attenzione che in altri linguaggi come ad esempio Java le parentesi angolari hanno un altro significato: in genere indicano l&#8217;uso di programmazione generica, qui invece significa che la classe adotta un determinato protocollo.</p>
<h3>Implementare più protocolli</h3>
<p>Una classe può implementare più protocolli:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a61390;">@interface</span> <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/"><span style="color: #400080;">NSData</span></a><span style="color: #002200;">:</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/"><span style="color: #400080;">NSObject</span></a> &lt;<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Protocols/NSCopying_Protocol/"><span style="color: #2a6f76;">NSCopying</span></a>, NSMutableCopying&gt; <span style="color: #002200;">&#123;</span><br />
....<br />
<span style="color: #002200;">&#125;</span><br />
<span style="color: #a61390;">@end</span></div></div>
<p>Quando dichiariamo una variabile o creiamo un metodo possiamo dire che quella variabile implementa un protocollo:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> draggingEnded<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> &lt;NSDraggingInfo&gt; <span style="color: #002200;">&#41;</span> sender;</div></div>
<p>Questo ci permette in fase di compilazione di controllare se il parametro che sto passando è conforme al protocollo indicato.</p>
<h3>Protocolli con metodo opzionali</h3>
<p>E&#8217; possibile utilizzare la keyword <strong>@optional</strong> per indicare che alcuni metodi specificati nel protocollo sono opzionali. Esiste anche la keyword <strong>@required</strong> per marcare il fatto che l&#8217;implementazione di un metodo è obbligatoria.</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a61390;">@protocol</span> MyProtocol<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> requiredMethod;<br />
@optional<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> anOptionalMethod;<br />
<span style="color: #a61390;">@end</span></div></div>
<p>La presenza di metodi opzionali solleva un potenziale problema nel momento in cui si opera su un oggetto che dovrebbe essere conforme ad un dato protocollo e noi vogliamo utilizzare un metodo opzionale.<br />
In questo caso non siamo sicuri che quel determinato oggetto lo implementi o meno. Bisogna verificare se quel metodo è implementato richiamando il metodo <strong>RespondsToSelector</strong></p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a61390;">id</span> &lt;MyProtocol&gt; o;<br />
<br />
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>o respondsToSelector<span style="color: #002200;">:</span> <span style="color: #a61390;">@selector</span> <span style="color: #002200;">&#40;</span>anOptionalMethod<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span><br />
<br />
<span style="color: #002200;">&#125;</span></div></div>
<h3>Approfondimenti</h3>
<p>Ecco tre brevi e semplici videocorsi sviluppati dai ragazzi di iMakeApps (<a href="http://www.imakeapps.it/video-corsi/" target="_blank" title="Visita il sito di iMakeApps">http://www.imakeapps.it/video-corsi/</a> ) </p>
<h4>I Protocolli in Objective C &#8211; Parte 1</h4>

	<script type="text/javascript">
		var flashvars = {};
		flashvars.playOnStart = "false";
		flashvars.startVolume = "70";
		flashvars.autoHideOther = "false";
		flashvars.autoHideVideoControls = "false";
		flashvars.onStartShowControls = "true";
		flashvars.fullVideoScale = "true";
		flashvars.showPlayButton = "true";
		flashvars.share = "false";
		flashvars.MediaLink2 = "http://www.youtube.com/watch?v=7pCDC4EaDSw";
		flashvars.image = "http://www.fimietta.it/blog/wp-content/plugins/youtube-with-style/lib/img.php?v=7pCDC4EaDSw";
		var params = {};
		params.bgcolor = "#000000";
		params.allowfullscreen = "true";
		params.wmode = "opaque";
		var attributes = {};
		attributes.id = "myplayer";
		swfobject.embedSWF("http://www.fimietta.it/blog/wp-content/plugins/youtube-with-style/lib/player.swf", "myAlternativeContent", "460", "310", "9.0.0", false, flashvars, params, attributes);
	</script> <div id="myAlternativeContent">blah</div>
<h4>I Protocolli in Objective C &#8211; Parte 2</h4>

	<script type="text/javascript">
		var flashvars = {};
		flashvars.playOnStart = "false";
		flashvars.startVolume = "70";
		flashvars.autoHideOther = "false";
		flashvars.autoHideVideoControls = "false";
		flashvars.onStartShowControls = "true";
		flashvars.fullVideoScale = "true";
		flashvars.showPlayButton = "true";
		flashvars.share = "false";
		flashvars.MediaLink2 = "http://www.youtube.com/watch?v=WNsP0Lz5J8c";
		flashvars.image = "http://www.fimietta.it/blog/wp-content/plugins/youtube-with-style/lib/img.php?v=WNsP0Lz5J8c";
		var params = {};
		params.bgcolor = "#000000";
		params.allowfullscreen = "true";
		params.wmode = "opaque";
		var attributes = {};
		attributes.id = "myplayer";
		swfobject.embedSWF("http://www.fimietta.it/blog/wp-content/plugins/youtube-with-style/lib/player.swf", "myAlternativeContent", "460", "310", "9.0.0", false, flashvars, params, attributes);
	</script> <div id="myAlternativeContent">blah</div>
<h4>I Protocolli in Objective C &#8211; Parte 3</h4>

	<script type="text/javascript">
		var flashvars = {};
		flashvars.playOnStart = "false";
		flashvars.startVolume = "70";
		flashvars.autoHideOther = "false";
		flashvars.autoHideVideoControls = "false";
		flashvars.onStartShowControls = "true";
		flashvars.fullVideoScale = "true";
		flashvars.showPlayButton = "true";
		flashvars.share = "false";
		flashvars.MediaLink2 = "http://www.youtube.com/watch?v=3Md8NVnWWu8";
		flashvars.image = "http://www.fimietta.it/blog/wp-content/plugins/youtube-with-style/lib/img.php?v=3Md8NVnWWu8";
		var params = {};
		params.bgcolor = "#000000";
		params.allowfullscreen = "true";
		params.wmode = "opaque";
		var attributes = {};
		attributes.id = "myplayer";
		swfobject.embedSWF("http://www.fimietta.it/blog/wp-content/plugins/youtube-with-style/lib/player.swf", "myAlternativeContent", "460", "310", "9.0.0", false, flashvars, params, attributes);
	</script> <div id="myAlternativeContent">blah</div>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/i-protocolli-in-objective-c-sono-molto-simili-alle-interfacce-di-java.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>19 &#8211; Strategia e Innovazione &#8211; Benefici della diversificazione: matrice BGC</title>
		<link>http://www.fimietta.it/blog/19-strategia-e-innovazione-benefici-della-diversificazione-matrice-bgc.html</link>
		<comments>http://www.fimietta.it/blog/19-strategia-e-innovazione-benefici-della-diversificazione-matrice-bgc.html#comments</comments>
		<pubDate>Sun, 13 Nov 2011 22:34:31 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[Strategia e Innovazione]]></category>
		<category><![CDATA[appunti del corso di strategia e innovazione]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2554</guid>
		<description><![CDATA[La matrice BCG è uno strumento utile per le strategie corporate delle imprese diversificate su diversi business in quanto permette di analizzare come utilizzare al meglio le risorse finanziarie per sostenere lo sviluppo e la redditività dell&#8217;impresa e quindi per decidere qual è la composizione ottimale del portafoglio di business. 
Per la crescita dell’impresa è [...]]]></description>
			<content:encoded><![CDATA[<p>La <strong>matrice BCG </strong>è uno strumento utile per le <strong>strategie corporate</strong> delle imprese diversificate su diversi business in quanto permette di <strong>analizzare come utilizzare al meglio le risorse finanziarie</strong> per sostenere lo <strong>sviluppo e la redditività dell&#8217;impresa</strong> e quindi per decidere qual è la <strong>composizione ottimale del portafoglio di business</strong>. </p>
<p>Per la crescita dell’impresa è fondamentale la capacità di <strong>autofinanziamento dell’impresa</strong> (cioè il reinvestimento degli utili generati), per <strong>ricorrere il meno possibile al credito, ai finanziamenti esterni.</strong></p>
<p><img src="http://www.fimietta.it/blog/wp-content/uploads/2011/11/matrice-bcg.jpg" alt="matrice-bcg" title="matrice-bcg" width="554" height="224" class="alignleft size-full wp-image-2556" /><br />
<span id="more-2554"></span></p>
<p>I parametri utilizzati per la classificazione sono:</p>
<ul>
<li>Il tasso di crescita del mercato t è il tasso di crescita delle vendite deflazionate (misura di attrattività del mercato).
<ul>
<li>Alto &#8211;> t > tasso di crescita del PIL nazionale</li>
<li>Basso &#8211;> t < PIL nazionale</li>
</ul>
</li>
<li>
 Quota di mercato relativa: confronto tra il fatturato aziendale derivante dalle vendite del<br />
prodotto con quello relativo allo stesso prodotto ottenuto dal rivale più grande operante nello<br />
stesso mercato (misura la forza dell’impresa in quel mercato).
</li>
</ul>
<p>Dalla combinazione di questi due elementi si possono individuare 4 tipi di attività:</p>
<ul>
<li>
<strong>Question Mark</strong>/<strong>Problem childs</strong>: sono attività con una bassa quota in mercati ad alta crescita.<br />
Richiedono investimenti per poter crescere e diventare Rising Stars</li>
<p>.</p>
<li><strong>Rising Stars</strong>: prodotti/attività con un&#8217;alta quota in mercati in forte crescita. Richiedono<br />
investimenti per continuare a crescere, per poi trasformarsi in Cash Cows.</li>
<li>
<strong>Cash Cow</strong>: attività con un&#8217;alta quota, in mercati a bassa crescita. Possono ritenersi attività di<br />
successo, che richiedono minori investimenti, più che altro &#8220;difensivi&#8221;.Sono &#8220;mucche&#8221; da cui &#8220;mungere&#8221; denaro per finanziare altre attività.</li>
<li><strong>Dogs</strong>: attività con una quota bassa in un mercato a bassa crescita. Possono generare profitti<br />
appena sufficienti al pareggio, o addirittura perdite, per cui il management potrebbe decidere di<br />
disinvestire.</li>
</ul>
<h3>Implicazioni manageriali della matrice BCG</h3>
<ol>
<li>Abbandonare i dogs</li>
<li>Le cash cows richiedono pochi investimenti, sono prodotti collocati su mercati maturi nei quali<br />
l’impresa può già contare sul raggiungimento di economie di esperienza</li>
<li>Le economie di esperienza su cui l’impresa può contare per i Problem Child sono limitati.<br />
Occorre accelerarne lo sviluppo di alcuni per migliorare l’apprendimento ed ampliarne la quota<br />
di mercato.</li>
<li>I profitti derivanti dalle Cash Cows possono essere reinvestiti per sostenere lo sviluppo delle<br />
Rising Stars e di alcuni Problem Childs e per ottenere su di essi “Economie di apprendimento”</li>
<li>Se l’impresa non ha sufficienti cash cows e problem childs deve prendere in considerazione la<br />
possibilità di fare acquisizioni o cessioni al fine di costruire un portafoglio equilibrato</li>
</ol>
<p><strong>Sequenza del Successo: Problem childs -> Rising Stars -> Cash Cows</strong></p>
<p><a href="http://www.fimietta.it/blog/wp-content/uploads/2011/11/matrice-bgc-sequenza-successo.jpg"><img src="http://www.fimietta.it/blog/wp-content/uploads/2011/11/matrice-bgc-sequenza-successo.jpg" alt="matrice-bgc-sequenza-successo" title="matrice-bgc-sequenza-successo" width="528" height="299" class="alignleft size-full wp-image-2558" /></a></p>
<p>
<strong>Sequenza del Disastro: Rising Stars -&gt; Question Mark -&gt; Dogs<br />
Cash Cows ->Dogs</strong><br />
</p>
<p><img src="http://www.fimietta.it/blog/wp-content/uploads/2011/11/matrice-bgc-sequenza-disastro.jpg" alt="matrice-bgc-sequenza-disastro" title="matrice-bgc-sequenza-disastro" width="538" height="284" class="alignleft size-full wp-image-2560" /></p>
<p>
<em>Questo modello presenta tuttavia dei limiti dato che spesso quattro quadranti semplificano eccessivamente la realtà e la maggior parte dei business si trova in situazioni intermedie.</em></p>
<p>L’intenzione di applicare questo modello potrebbe portare a forzature e quindi ad una catalogazione errata dei prodotti.</p>
<p>Inoltre essere <strong>market leader</strong> in un business con tassi di crescita bassi non implica avere una cash cow da spremere in quanto potrebbe essere necessario reinvestire per difendere, oppure pressioni su prezzi e margini potrebbero prosciugare il cash.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/19-strategia-e-innovazione-benefici-della-diversificazione-matrice-bgc.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>18 &#8211; Strategia e Innovazione &#8211; Scelta del tempo di ingresso nel mercato &#8211; I FIRST MOVER</title>
		<link>http://www.fimietta.it/blog/18-strategia-e-innovazione-scelta-del-tempo-di-ingresso-nel-mercato-i-first-mover.html</link>
		<comments>http://www.fimietta.it/blog/18-strategia-e-innovazione-scelta-del-tempo-di-ingresso-nel-mercato-i-first-mover.html#comments</comments>
		<pubDate>Sun, 13 Nov 2011 22:30:20 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[Strategia e Innovazione]]></category>
		<category><![CDATA[appunti del corso di strategia e innovazione]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2550</guid>
		<description><![CDATA[Le variabili rilevanti nella scelta del tempo di ingresso nel mercato sono:

Quali sono i possibili vantaggi e le possibili criticità legate ad un’entrata in un mercato come
first-mover
Quanto velocemente si arriverà al “flesso” della curva ad S di adozione
Qual è la capacità dell’azienda di sostenere perdite finanziarie iniziali mediante i profitti
derivanti dalla vendita di altri prodotti
Qual [...]]]></description>
			<content:encoded><![CDATA[<p>Le variabili rilevanti nella scelta del tempo di ingresso nel mercato sono:</p>
<ul>
<li>Quali sono i possibili vantaggi e le possibili criticità legate ad un’entrata in un mercato come<br />
first-mover</li>
<li>Quanto velocemente si arriverà al “flesso” della curva ad S di adozione</li>
<li>Qual è la capacità dell’azienda di sostenere perdite finanziarie iniziali mediante i profitti<br />
derivanti dalla vendita di altri prodotti</li>
<li>Qual è la capacità di individuare in anticipo le variabili di prestazioni più importanti e òe<br />
preferenze dei consumatori
</li>
</ul>
<p><span id="more-2550"></span><br />
<img src="http://www.fimietta.it/blog/wp-content/uploads/2011/11/barra.png" alt="appunti di strategia e innovazione" title="appunti di strategia e innovazione" width="550" height="16" class="alignleft size-full wp-image-2614" /></p>
<h3>Possibili VANTAGGI dei FIRST MOVERS</h3>
<ul>
<li>Maggiore facilità ad imporre un disegno dominante nei mercati dove esistono esternalità di<br />
rete (effetto di lock-in) e notevoli economie di apprendimento.
</li>
<li>Il first mover può imporre costi di switching al cliente e sfruttare gli effetti positivi legati al<br />
consolidamento delle preferenze del cliente.
</li>
<li>Vantaggio di posizione nella corsa alle risorse scarse</li>
<li>Effetti positivi sulla reputazione dell’impresa (particolarmente importanti per beni<br />
esperienza)</li>
<li>Economia di scala in mercati maturi rendono economicamente “non sostenibile” la rincorsa<br />
di un nuovo entrante</li>
</ul>
<h3>Individuare nuovi mercati emergenti</h3>
<p>Il first mover deve spesso trovare mercati emergenti, però è impossibile analizzare mercati che non<br />
esistono quindi:</p>
<p>Le ricerche di mercato e le previsioni di vendita di un nuovo prodotto in tale mercato sono<br />
inattendibili</p>
<ul>
<li>È impossibile utilizzare il cliente come fonte di apprendimento (non conosce il prodotto e<br />
non ha mai pensato a possibili ambiti di applicazione)</li>
<li>Le strategie di successo emergono in modo non deliberato</li>
</ul>
<p>Ciò implica che le strategie di entrata in un mercato che non esiste ancora hanno un elevato tasso di<br />
fallimento e si rendono necessarie alcune “false partenze” prima di individuare un’applicazione di<br />
successo per il prodotto.<br />
A tal fine è importante vedere come i clienti pilota utilizzano il prodotto piuttosto che ascoltare<br />
quanto questi dicono.</p>
<h3>SVANTAGGI del FIRST MOVER</h3>
<p>Devono sostenere <strong>elevati costi di ricerca e sviluppo</strong> e successivamente c’è uno <strong>spillover di conoscenza</strong> a favore delle imprese che seguono il <strong>first mover</strong> dato che esistono fenomeni di apprendimento collettivo a livello di settore.</p>
<p>Inoltre il <strong>first mover </strong>ha la necessità di sviluppare la filiera industriale sia a monte che a valle (<strong>deve cioè creare la “catena del valore”</strong>).<br />
Inoltre essendo un mercato inesplorato c’è penuria di asset complementari e di tecnologie abilitanti nonché forte incertezza nelle condizioni della domanda.</p>
<p><strong>Per avere successo il first mover deve comprendere velocemente le dimensioni del valore per il<br />
cliente e deve essere in grado di assorbire le perdite iniziali</strong> (maggiore nelle imprese diversificate -> matrice BCG):</p>
<ul>
<li>Accesso a finanziamenti interni od esterni</li>
<li>Criticità della situazione di liquidità</li>
</ul>
<p>Inoltre altri vantaggi che favoriscono le grandi aziende come first mover sono la serie storica sulle performance dell’impresa (<strong>track record</strong>) come indicatore per clienti, fornitori e distributori e la capacità di costruire velocemente una buona <strong>brand reputation</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/18-strategia-e-innovazione-scelta-del-tempo-di-ingresso-nel-mercato-i-first-mover.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

