<?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>RudiYardley.com &#187; Flex</title>
	<atom:link href="http://blog.rudiyardley.com/category/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rudiyardley.com</link>
	<description>Technical tidbits on Flash, Flex, Application Development, MODx, Silverstripe and Freelancing</description>
	<lastBuildDate>Tue, 31 Jan 2012 04:31:03 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Organising your Data Access Layer in an AIR Flex Application</title>
		<link>http://blog.rudiyardley.com/2011/03/organising-your-data-access-layer-in-a-air-flex-application/</link>
		<comments>http://blog.rudiyardley.com/2011/03/organising-your-data-access-layer-in-a-air-flex-application/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 04:40:24 +0000</pubDate>
		<dc:creator>rudi</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Software Design]]></category>

		<guid isPermaLink="false">http://blog.rudestar.net/?p=481</guid>
		<description><![CDATA[With the advent of AIR technologies, the Flex developer now has the ability to save data to the bundled SQLite relational database, which is pretty much a requirement for any desktop application these days. Many Flex developers like myself that come from a Flash or front end background, may not necessarily be familiar with the [...]]]></description>
			<content:encoded><![CDATA[<p>With the advent of AIR technologies, the Flex developer now has the ability to save data to the bundled SQLite relational database, which is pretty much a requirement for any desktop application these days. Many Flex developers like myself that come from a Flash or front end background, may not necessarily be familiar with the design patterns involved in accessing and mapping data to and from a relational database. The examples that come in the AIR documentation only deliver the basic usecase to demonstrate language features and don&#8217;t always apply the necessary level of abstraction to come up with solutions that are elegant, hide complexity sufficiently and allow for great scalability.</p>
<p>For areas of common standard functionality, where the project maintenance is likely to change hands, I usually recommend using a well built and well documented framework when building Rich Applications but know how important it is to understand the underlying architecture and design patterns a framework uses so as to have a better understanding of any given system. There are a few ORM (Object Relational Mapping) solutions for AIR emerging on the market now such as <a href="http://flexorm.riaforge.org/">FlexORM</a> that have caught my eye, many of them using annotations to map classes to database records but what sort of complexity are those ORM solutions managing?</p>
<p>I have recently been reading Martin Fowler&#8217;s excellent book <a href="http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420">Patterns of Enterprise Application Architecture</a> and saw several things I could bring to my own application development toolkit. So in order to better understand the patterns suggested by Fowler, I decided to test the waters and build a basic custom ORM system that I could use on small bespoke projects such as my own projects, where I would be in control of maintenance. Fowler mentions several patterns including Active Record, Data Mapper, Unit of Work, Lazy Load plus many others devoted to the specifics of relational mapping.</p>
<p>Upon researching the subject, it appears that fundamental to the architecture or your Data Access Layer is the decision of whether to follow <a href="http://en.wikipedia.org/wiki/Active_Record">Active Record</a> or <a href="http://martinfowler.com/eaaCatalog/dataMapper.html">Data Mapper</a>. Now generally, I am not a huge fan of Active Record for a couple of reasons; firstly, from my experiences with Silverlight and Cake it tends to lead to an oversimplification of the data structure, which often means the data of your application does not represent the problem domain accurately. Since the key to developing a quality app is getting the data structure correct, this will likely affect the optimizability and maintainability of your application in the long run. Secondly Active Record breaks the Principle of Single Responsibility within Object Oriented Programming which brings class bloat as model classes cope with both the Domain based business rules as well as the responsibilities of mapping to the database. So since using Active Record does not feel to me like a best practice, we are left with using Data Mapper to structure the data access layer.</p>
<p>So with a Data Mapper approach chosen, from then on in what are the patterns that are the most important to success on a basic level? How should you structure simple projects where you want an organised data layer but don&#8217;t know where to start? Let&#8217;s break it down into components:</p>
<h2>Controlling what needs to be done: Unit Of Work</h2>
<p>The Unit of Work Pattern takes a domain object and flags that domain object for an action by the appropriate Data Mapper without actually doing the action until it&#8217;s commit() method is called. This way database calls may be managed using bulk transactions limiting individual transactions. UnitOfWork&#8217;s main two functional modes are that of flagging objects that are out out of sync with the DB and committing the queued changes to the database. This has the effect of making fewer database&nbsp;transactions as transactions can be postponed till all the relevant fields are changed and the commit function is run. When you can imagine that the alternative would be to run a transaction every single time a field is changed you can see quickly how this pattern can help speed things up. The Unit of Work has methods for managing new,dirty and deleted objects as you can see here:</p>
<h6>Fig. 1.1 Unit if Work UML</h6>
<p><a href="http://blog.rudestar.net/wp-content/uploads//UnitOfWork.jpg"><img class="alignnone size-full wp-image-493" title="UnitOfWork" src="http://blog.rudestar.net/wp-content/uploads//UnitOfWork.jpg" alt="UnitOfWork" width="225" height="140" /></a></p>
<h6>Fig. 1.2 Unit of Work Actionscript Class</h6>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow"><ol><li></li><li>package com.rudiyardley.dbapp.db</li><li><span class="br0">&#123;</span></li><li>	import com.rudiyardley.dbapp.model.DomainObject;</li><li>	import com.rudiyardley.dbapp.model.Student;</li><li>&nbsp;</li><li>	public class UnitOfWork</li><li>	<span class="br0">&#123;</span></li><li>&nbsp;</li><li>		private var newObjects:Array;</li><li>		private var dirtyObjects:Array;</li><li>		private var deletedObjects:Array;</li><li>&nbsp;</li><li>		public var identityMap:IIdentityMap;</li><li>&nbsp;</li><li>		public function UnitOfWork<span class="br0">&#40;</span>s:ForceSingle<span class="br0">&#41;</span></li><li>		<span class="br0">&#123;</span></li><li>			newObjects = new Array<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>			dirtyObjects = new Array<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>			deletedObjects = new Array<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>		<span class="br0">&#125;</span></li><li>&nbsp;</li><li>		public function registerDirty<span class="br0">&#40;</span>object:DomainObject<span class="br0">&#41;</span>:void</li><li>		<span class="br0">&#123;</span></li><li>			dirtyObjects.push<span class="br0">&#40;</span>object<span class="br0">&#41;</span>;</li><li>		<span class="br0">&#125;</span></li><li>&nbsp;</li><li>		public function registerClean<span class="br0">&#40;</span>object:DomainObject<span class="br0">&#41;</span>:void</li><li>		<span class="br0">&#123;</span></li><li>			dirtyObjects.splice<span class="br0">&#40;</span>dirtyObjects.indexOf<span class="br0">&#40;</span>object<span class="br0">&#41;</span>,1<span class="br0">&#41;</span>;</li><li>		<span class="br0">&#125;</span></li><li>&nbsp;</li><li>		public function registerDeleted<span class="br0">&#40;</span>object:DomainObject<span class="br0">&#41;</span>:void</li><li>		<span class="br0">&#123;</span></li><li>			deletedObjects.push<span class="br0">&#40;</span>object<span class="br0">&#41;</span>;</li><li>		<span class="br0">&#125;</span></li><li>&nbsp;</li><li>		//	Object will be placed in the DB with an insert statement</li><li>		public function registerNew<span class="br0">&#40;</span>object:DomainObject<span class="br0">&#41;</span>:void</li><li>		<span class="br0">&#123;</span></li><li>			newObjects.push<span class="br0">&#40;</span>object<span class="br0">&#41;</span>;</li><li>			registerClean<span class="br0">&#40;</span>object<span class="br0">&#41;</span>;</li><li>		<span class="br0">&#125;</span></li><li>&nbsp;</li><li>		public function commit<span class="br0">&#40;</span><span class="br0">&#41;</span>:void</li><li>		<span class="br0">&#123;</span></li><li>			var mapper:IDataMapper;</li><li>			var object:DomainObject;</li><li>&nbsp;</li><li>			while<span class="br0">&#40;</span>newObjects.length&gt;0<span class="br0">&#41;</span></li><li>			<span class="br0">&#123;</span></li><li>				object = newObjects.shift<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>				mapper = DataSession.current.getMapper<span class="br0">&#40;</span>object<span class="br0">&#41;</span>;</li><li>				mapper.create<span class="br0">&#40;</span>object<span class="br0">&#41;</span>;</li><li>			<span class="br0">&#125;</span></li><li>&nbsp;</li><li>			while<span class="br0">&#40;</span>dirtyObjects.length&gt;0<span class="br0">&#41;</span></li><li>			<span class="br0">&#123;</span></li><li>				object = dirtyObjects.shift<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>				mapper = DataSession.current.getMapper<span class="br0">&#40;</span>object<span class="br0">&#41;</span>;</li><li>				mapper.update<span class="br0">&#40;</span>object<span class="br0">&#41;</span>;</li><li>			<span class="br0">&#125;</span></li><li>&nbsp;</li><li>&nbsp;</li><li>			while<span class="br0">&#40;</span>deletedObjects.length&gt;0<span class="br0">&#41;</span></li><li>			<span class="br0">&#123;</span></li><li>				object = deletedObjects.shift<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>				mapper = DataSession.current.getMapper<span class="br0">&#40;</span>object<span class="br0">&#41;</span>;</li><li>				mapper.deleteItem<span class="br0">&#40;</span>object<span class="br0">&#41;</span>;				</li><li>			<span class="br0">&#125;</span></li><li>&nbsp;</li><li>		<span class="br0">&#125;</span></li><li>	<span class="br0">&#125;</span></li><li><span class="br0">&#125;</span></li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<h2>Reading to and From the Database: DataMapper</h2>
<p>How do you interface with the DB so that your persistence logic is separate from your application yet not acting as a transactional mess? A data mapper is responsible for translating between domain objects and the database. Usually you will have one class per domain object. You put in an object in the appropriate accessor method and the DataMapper creates,reads,updates or deletes it. Note the data mapper is usually object specific and every persistent DomainObject should have a corresponding DataMapper. DataMappers should live within the DataSession and can also maintain identity maps there for caching whenever reading from the database.</p>
<h6>Fig. 1.3 A typical abstract DataMapper:</h6>
<p><a href="http://blog.rudestar.net/wp-content/uploads//DataMapper1.jpg"><img class="alignnone size-full wp-image-498" title="DataMapper" src="http://blog.rudestar.net/wp-content/uploads//DataMapper1.jpg" alt="DataMapper" width="225" height="132" /></a></p>
<p>The DataMapper above represents the main things you will tend to need from a data mapper. A specific mapper may contain more methods depending on what type of searches it requires. A Domain Object&#8217;s corresponding mapper should contain the logic for building all the SQL responsible for it&#8217;s persistence in the database. An easy way to prepare and select appropriate mappers is to have some kind of Factory Method on the DataSession object that accepts a Class reference and spits out a mapper. ie.<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow"><ol><li></li><li>DataSession.current.getMapper<span class="br0">&#40;</span>GalleryImage<span class="br0">&#41;</span>;	// Would return a GalleryImage mapper.</li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<h6>Fig. 1.4 Source of a typical DataMapper</h6>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow"><ol><li></li><li>package com.rudiyardley.dbapp.db</li><li><span class="br0">&#123;</span></li><li>	import com.rudiyardley.dbapp.model.DomainObject;</li><li>	import com.rudiyardley.dbapp.model.Student;</li><li>&nbsp;</li><li>	import flash.data.SQLConnection;</li><li>	import flash.data.SQLResult;</li><li>	import flash.data.SQLStatement;</li><li>&nbsp;</li><li>	import mx.collections.ArrayCollection;</li><li>&nbsp;</li><li>	public class StudentMapper implements IDataMapper</li><li>	<span class="br0">&#123;</span></li><li>		private var stmtInit:SQLStatement;</li><li>		private var stmtCreate:SQLStatement;</li><li>		private var stmtUpdate:SQLStatement;</li><li>		private var stmtDeleteItem:SQLStatement;</li><li>		private var stmtReadAll:SQLStatement;</li><li>		private var stmtReadById:SQLStatement;</li><li>&nbsp;</li><li>		private var map:IIdentityMap;</li><li>&nbsp;</li><li>		public function StudentMapper<span class="br0">&#40;</span>conn:SQLConnection,map:IIdentityMap<span class="br0">&#41;</span></li><li>		<span class="br0">&#123;</span></li><li>			this.map = map;</li><li>&nbsp;</li><li>			//	Initialize the other queries</li><li>			stmtInit = new SQLStatement<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>			stmtCreate = new SQLStatement<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>			stmtUpdate = new SQLStatement<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>			stmtDeleteItem = new SQLStatement<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>			stmtReadAll = new SQLStatement<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>			stmtReadById = new SQLStatement<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>&nbsp;</li><li>			//	apply the connection</li><li>			stmtInit.sqlConnection = conn;</li><li>			stmtCreate.sqlConnection = conn;</li><li>			stmtUpdate.sqlConnection = conn;</li><li>			stmtDeleteItem.sqlConnection = conn;</li><li>			stmtReadAll.sqlConnection = conn;</li><li>			stmtReadById.sqlConnection = conn;</li><li>&nbsp;</li><li>			initDB<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>&nbsp;</li><li>		<span class="br0">&#125;</span></li><li>&nbsp;</li><li>		//	CREATE TABLE</li><li>		private function initDB<span class="br0">&#40;</span><span class="br0">&#41;</span>:void</li><li>		<span class="br0">&#123;</span></li><li>			stmtInit.text = &quot;CREATE TABLE IF NOT EXISTS students <span class="br0">&#40;</span> id TEXT PRIMARY KEY, name TEXT <span class="br0">&#41;</span>; &quot;;</li><li>			stmtInit.execute<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>		<span class="br0">&#125;</span></li><li>&nbsp;</li><li>		//	READ ALL</li><li>		public function readAll<span class="br0">&#40;</span><span class="br0">&#41;</span>:ArrayCollection</li><li>		<span class="br0">&#123;</span></li><li>			var result:SQLResult;</li><li>			var items:ArrayCollection;</li><li>			var i:int;</li><li>			var dataObject:Object;</li><li>			var currentStudent:Student;</li><li>&nbsp;</li><li>			//	Prepare statement</li><li>			stmtReadAll.text = &quot;SELECT * FROM students;&quot;;</li><li>			stmtReadAll.execute<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>&nbsp;</li><li>			//	Get results and iterate over result</li><li>			result = stmtReadAll.getResult<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>			items = new ArrayCollection<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>			if<span class="br0">&#40;</span>result.data != null<span class="br0">&#41;</span></li><li>			<span class="br0">&#123;</span></li><li>				for<span class="br0">&#40;</span>i=<span style="">0</span>;i&lt;result.data.length;i++<span class="br0">&#41;</span></li><li>				<span class="br0">&#123;</span></li><li>					dataObject = result.data<span class="br0">&#91;</span>i<span class="br0">&#93;</span>;</li><li>					currentStudent = createCleanDomainObjectFromDataObject<span class="br0">&#40;</span>dataObject<span class="br0">&#41;</span> as Student;</li><li>					DataSession.current.registerObject<span class="br0">&#40;</span>currentStudent<span class="br0">&#41;</span>;</li><li>					items.addItem<span class="br0">&#40;</span>currentStudent<span class="br0">&#41;</span>;</li><li>				<span class="br0">&#125;</span></li><li>			<span class="br0">&#125;</span></li><li>			return items;</li><li>		<span class="br0">&#125;</span></li><li>&nbsp;</li><li>		//	READ BY ID</li><li>		public function readById<span class="br0">&#40;</span>id:String<span class="br0">&#41;</span>:DomainObject</li><li>		<span class="br0">&#123;</span></li><li>			var result:SQLResult;</li><li>			var studentToReturn:Student;</li><li>			var dataObject:Object;</li><li>&nbsp;</li><li>			studentToReturn = map.getObjectByTypeId<span class="br0">&#40;</span>Student,id<span class="br0">&#41;</span> as Student;</li><li>&nbsp;</li><li>			if<span class="br0">&#40;</span>studentToReturn != null<span class="br0">&#41;</span></li><li>			<span class="br0">&#123;</span></li><li>				return studentToReturn;</li><li>			<span class="br0">&#125;</span></li><li>&nbsp;</li><li>			stmtReadById.text = &quot;SELECT * FROM students WHERE id=:id;&quot;;</li><li>			stmtReadById.parameters<span class="br0">&#91;</span>&quot;:id&quot;<span class="br0">&#93;</span> = id;</li><li>			stmtReadById.execute<span class="br0">&#40;</span>1<span class="br0">&#41;</span>;</li><li>&nbsp;</li><li>&nbsp;</li><li>			result = stmtReadById.getResult<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>			if<span class="br0">&#40;</span>result.data == null<span class="br0">&#41;</span></li><li>			<span class="br0">&#123;</span></li><li>				return null;</li><li>			<span class="br0">&#125;</span></li><li>			stmtReadById.cancel<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>			dataObject = result.data<span class="br0">&#91;</span>0<span class="br0">&#93;</span>;</li><li>			studentToReturn = createCleanDomainObjectFromDataObject<span class="br0">&#40;</span>result.data<span class="br0">&#91;</span>0<span class="br0">&#93;</span><span class="br0">&#41;</span> as Student;</li><li>			DataSession.current.registerObject<span class="br0">&#40;</span>studentToReturn<span class="br0">&#41;</span>;</li><li>			return studentToReturn;</li><li>		<span class="br0">&#125;</span></li><li>&nbsp;</li><li>		//	CREATE</li><li>		public function create<span class="br0">&#40;</span>object:DomainObject<span class="br0">&#41;</span>:void</li><li>		<span class="br0">&#123;</span></li><li>			if<span class="br0">&#40;</span>readById<span class="br0">&#40;</span>object.id<span class="br0">&#41;</span>==null<span class="br0">&#41;</span></li><li>			<span class="br0">&#123;</span></li><li>				stmtCreate.text = &quot;INSERT INTO students <span class="br0">&#40;</span>id,name<span class="br0">&#41;</span> VALUES <span class="br0">&#40;</span>:id,:name<span class="br0">&#41;</span>;&quot;;</li><li>				stmtCreate.parameters<span class="br0">&#91;</span>&quot;:id&quot;<span class="br0">&#93;</span> = Student<span class="br0">&#40;</span>object<span class="br0">&#41;</span>.id;</li><li>				stmtCreate.parameters<span class="br0">&#91;</span>&quot;:name&quot;<span class="br0">&#93;</span> = Student<span class="br0">&#40;</span>object<span class="br0">&#41;</span>.name;</li><li>				stmtCreate.execute<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>			<span class="br0">&#125;</span></li><li>		<span class="br0">&#125;</span></li><li>&nbsp;</li><li>		//	UPDATE</li><li>		public function update<span class="br0">&#40;</span>object:DomainObject<span class="br0">&#41;</span>:void</li><li>		<span class="br0">&#123;</span></li><li>			stmtUpdate.text = &quot;UPDATE students SET name=:name WHERE id=:id; &quot;;</li><li>			stmtUpdate.parameters<span class="br0">&#91;</span>&quot;:id&quot;<span class="br0">&#93;</span> = Student<span class="br0">&#40;</span>object<span class="br0">&#41;</span>.id;</li><li>			stmtUpdate.parameters<span class="br0">&#91;</span>&quot;:name&quot;<span class="br0">&#93;</span> = Student<span class="br0">&#40;</span>object<span class="br0">&#41;</span>.name;</li><li>			stmtUpdate.execute<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>		<span class="br0">&#125;</span>;</li><li>&nbsp;</li><li>		//	DELETE</li><li>		public function deleteItem<span class="br0">&#40;</span>object:DomainObject<span class="br0">&#41;</span>:void</li><li>		<span class="br0">&#123;</span></li><li>&nbsp;</li><li>			stmtDeleteItem.text = &quot;DELETE FROM students WHERE id = :id ; &quot;;</li><li>			stmtDeleteItem.parameters<span class="br0">&#91;</span>&quot;:id&quot;<span class="br0">&#93;</span> = Student<span class="br0">&#40;</span>object<span class="br0">&#41;</span>.id;</li><li>			stmtDeleteItem.execute<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>		<span class="br0">&#125;</span>;</li><li>&nbsp;</li><li>		//	Utility function creates a clean domain object</li><li>		private function createCleanDomainObjectFromDataObject<span class="br0">&#40;</span>dataObject:Object<span class="br0">&#41;</span>:DomainObject</li><li>		<span class="br0">&#123;</span></li><li>			var student:Student = new Student<span class="br0">&#40;</span>dataObject.id,dataObject.name<span class="br0">&#41;</span>;</li><li>			student.markClean<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li>			return student;</li><li>		<span class="br0">&#125;</span></li><li>	<span class="br0">&#125;</span></li><li><span class="br0">&#125;</span></li><li>&nbsp;</li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<h3>Handling ID&#8217;s using GUIDS</h3>
<p>One of the issues I found in working with the fowler patterns was that when doing basic bulk writes or reads Actionscript APIs don&#8217;t allow access to the most recent row ID of a record until the entire transaction has been completed. A strategy I found to solve this problem was to create ID&#8217;s external to the database. One way to do this was to incrementally update a purpose created field the database every time a record was added to keep track of the currently written id. A simpler method was to use a GUID generator to accomplish the same ends.<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow"><ol><li></li><li>var s:Student = new Student<span class="br0">&#40;</span>IdGenerator.instance.getId<span class="br0">&#40;</span><span class="br0">&#41;</span>,name<span class="br0">&#41;</span>;</li><li></li></ol></div></pre><!--END_DEVFMTCODE--><br />
For your information the GUID creator I use comes from <a href="http://www.rgbeffects.com/blog/actionscript/actionscript-3-guid-%E2%80%93-generating-unique-ids-for-users-in-as3/">RGBlog</a>.</p>
<h3>Keeping track of identities: IdentityMap</h3>
<p>When you have objects that represent objects within the database it is important to keep track of all the objects out there in memory. To this end we can use a registry associated with the data session.</p>
<h3>Downloadable Example</h3>
<p>I have put together an example of a data access layer within the context of a simple and rather hastily constructed application that can act as an example of the patterns at work here. The application manages a many to many relationship between Teachers and Students. To use the application you can create Teachers or Students and the application adds them to the lists. Then select both a teacher and student together and you can create a relationship.</p>
<p>You can download the source code <a href="/wp-content/uploads/DataApplication.zip?phpMyAdmin=rutTBiA3QroFIysWggFI8Rzcq40" target="_blank">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rudiyardley.com/2011/03/organising-your-data-access-layer-in-a-air-flex-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What is Flex?</title>
		<link>http://blog.rudiyardley.com/2010/01/what-is-flex/</link>
		<comments>http://blog.rudiyardley.com/2010/01/what-is-flex/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 12:52:56 +0000</pubDate>
		<dc:creator>rudi</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://blog.rudestar.net/?p=351</guid>
		<description><![CDATA[I suppose sometimes as a Flex or Flash developer you are so immersed in the whole SWF ecosystem that occasionally you get asked a question that should be easy to answer but becomes difficult to explain to someone without a technical perspective.
The other day I was preparing a spec and getting a colleague to double [...]]]></description>
			<content:encoded><![CDATA[<p>I suppose sometimes as a Flex or Flash developer you are so immersed in the whole SWF ecosystem that occasionally you get asked a question that should be easy to answer but becomes difficult to explain to someone without a technical perspective.</p>
<p>The other day I was preparing a spec and getting a colleague to double check my correspondence. They brought up that the client likely did not know what Flex was and that I should be prepared to explain it to the client in the meeting we were tabled to have. My first reaction was fine until it dawned upon me that finding the words to describe flex for someone who only really understands flash as a scripting and animation technology may actually be a little difficult so thought I would share with you what I came up with as well as ask for opinions on the matter.</p>
<p>Here are a few possible answers:</p>
<ol>
<li>Flex is a collection of compilers that output SWF bitecode</li>
<li>Flex is a framework that is based on MXML as a meta-language for forming SWF bytecode</li>
<li>The Flex framework uses both MXML and a bunch of custom Actionscript classes to define the various visual and non-visual elements of Rich Applications</li>
<li>Flex makes building Rich applications with Flash faster by leveraging the use of standard user interface components and layout method</li>
</ol>
<p>Any other thoughts?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rudiyardley.com/2010/01/what-is-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

