Apparently there are no rules. Just call it MVC and it's MVC I guess.
Ross P. Sclafani Owner / Creative Director Neuromantic Industries http://www.neuromantic.com http://ross.sclafani.net http://www.twitter.com/rosssclafani 347.204.5714 On Feb 24, 2012, at 10:15 AM, "Merrill, Jason" <jason.merr...@bankofamerica.com> wrote: > Maybe I'm off, but I don't think the controller should manipulate data. > > Jason Merrill > Instructional Technology Architect II > Bank of America Global Learning > > > > > > _______________________ > > -----Original Message----- > From: flashcoders-boun...@chattyfig.figleaf.com > [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Mattheis, > Erik (MIN-WSW) > Sent: Thursday, February 23, 2012 8:26 PM > To: Flash Coders List > Subject: Re: [Flashcoders] MVC style Correction > > "Ross Sclafani" <ross.sclaf...@gmail.com> wrote: > It is very easy to locate any code in one of my projects by ascertaining the > domain of the code in question and looking in the appropriate branch. > Does it store data? It's in the model. Does it interpret and display data? > Try your views. Does it manipulate data? Look in the controller. > > This thread has been useful, thanks all. I've a ton of questions regarding > judgment calls and below I post a class illustrating a few I've struggled > with. The comments are intended to be my questions/admissions of bafflement. > I'm unsure where in a MVC this class should go as its main purpose is to work > with the File class which itself has methods which retrieve > (File.applicationDirectory), interpret (File.exists) and display > (File.browseForOpen) data. > > The class also is a dreaded example of allowing the view to listen directly > to the model for events, perhaps only because I've misguidedly decided to > make it part of the model as it has to do with copying and deleting a SQLite > file used in the app. > > package mvc.model { > /* saveFileAs() saves a copy of a SQLite DB for the purposes of transferring > data to an instance of this app on another computer. > > closeDBAndReplace() = replaces the db file if the user is importing data. > */ > import flash.events.EventDispatcher; > import flash.events.Event; > import flash.filesystem.File; > // class Data works with a SQLite DB > import mvc.model.Data; > // Where in a MVC should custom event classes // be located? I wish to pass > my own objects // along with events, usually "Transfer Objects" > // or a string to be displayed > import mvc.controller.CustomDataEvent; > > public class ManipulateDBFile extends EventDispatcher { > > private var _data:Data; > private var _sourceFile:File; > private var _copyToDirectory:File; > > public function ManipulateDBFile(data:Data) { > _data = data; > } > > public function saveFileAs() : void { > var docsDir:File = File.desktopDirectory; > // This creates a UI element. I would look for this code in the view! > docsDir.browseForDirectory('Save File in ...'); > // This is asking a UI elemt to inform the Model directly. Big bad no? > docsDir.addEventListener(Event.SELECT, copyFile); > } > > private function copyFile(e:Event):void { > _sourceFile = File.applicationStorageDirectory.resolvePath("msgDB.db"); > _copyToDirectory = e.target.resolvePath("msgDB.db"); > if (_copyToDirectory.exists) { > // Passing this event through the Controller seems to create complexity, > // or at least unnecessary lines of code. Is there an advantage gained by > // communicating to the view through the controller here? > var evt:CustomDataEvent = new > CustomDataEvent(CustomDataEvent.FILE_ALREADY_EXISTS); > dispatchEvent(evt); > } > else { > replaceFile(); > } > } > > public function replaceFile() : void { > var evt:CustomDataEvent = new > CustomDataEvent(CustomDataEvent.COPY_COMPLETE); > try { > _sourceFile.copyTo(_copyToDirectory, true); > dispatchEvent(evt); > } > > catch (error:Error) { > evt.param = error.message; > dispatchEvent(evt); > } > _sourceFile = null; > _copyToDirectory = null; > } > > public function closeDBAndReplace() : void { > // The file cannot be deleted if there is a SQLConnection to it. > // The class that is aware of a possible connection also does the > // deletion. But deleting the file seems to conceptually > // fit into this class better > _data.addEventListener(CustomDataEvent.DRILL_RESET, findFile, false, 0, > true); > _data.deleteDBFile(); > > } > > private function findFile(e:CustomDataEvent) : void { > _data.removeEventListener(CustomDataEvent.DRILL_RESET, findFile, false); > var docsDir:File = File.desktopDirectory; > docsDir.browseForOpen('Select msgDB.db file ...'); > docsDir.addEventListener(Event.SELECT, replaceDBFile); > } > > private function replaceDBFile(e:Event):void { > var sourceFile:File = e.target as File; > var destination:File = > File.applicationStorageDirectory.resolvePath("msgDB.db"); > try { > sourceFile.copyTo(destination, true); > dispatchEvent(new CustomDataEvent(CustomDataEvent.RESTART_REQUIRED)); > } > catch (error:Error) { > trace("Error:", error.message); > } > } > } > } > > On 2/17/12 6:07 PM, "Ross Sclafani" <ross.sclaf...@gmail.com> wrote: > It is very easy to locate any code in one of my projects by ascertaining the > domain of the code in question and looking in the appropriate branch. > Does it store data? It's in the model. > Does it interpret and display data? Try your views. > Does it manipulate data? Look in the controller. > > > > _ _ _ > Erik Mattheis | Weber Shandwick > P: (952) 346.6610 > M: (612) 377.2272 > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > ---------------------------------------------------------------------- > This message w/attachments (message) is intended solely for the use of the > intended recipient(s) and may contain information that is privileged, > confidential or proprietary. If you are not an intended recipient, please > notify the sender, and then please delete and destroy all copies and > attachments, and be advised that any review or dissemination of, or the > taking of any action in reliance on, the information contained in or attached > to this message is prohibited. > Unless specifically indicated, this message is not an offer to sell or a > solicitation of any investment products or other financial product or > service, an official confirmation of any transaction, or an official > statement of Sender. Subject to applicable law, Sender may intercept, > monitor, review and retain e-communications (EC) traveling through its > networks/systems and may produce any such EC to regulators, law enforcement, > in litigation and as required by law. > The laws of the country of each sender/recipient may impact the handling of > EC, and EC may be archived, supervised and produced in countries other than > the country in which you are located. This message cannot be guaranteed to be > secure or free of errors or viruses. > > References to "Sender" are references to any subsidiary of Bank of America > Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are > Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a > Condition to Any Banking Service or Activity * Are Not Insured by Any Federal > Government Agency. Attachments that are part of this EC may have additional > important disclosures and disclaimers, which you should read. This message is > subject to terms available at the following link: > http://www.bankofamerica.com/emaildisclaimer. By messaging with Sender you > consent to the foregoing. > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders