- 浏览: 154394 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
zyq070:
version 自动增长的 你手动设值 相比之前的值已经变化 ...
Row was updated or deleted by another transaction (or unsaved-value mapping was -
中华神韵:
...
Java中从一个ArrayList删除重复的元素 -
Menuz:
logcat慢慢调,终会找到的。
The application has stopped unexpectedly -
右转随缘:
好抽象。。。
The application has stopped unexpectedly -
tsmg:
您好,我zend也配了,怎么就是不能正常调试呢?是不会用在EP ...
安装EPP的调试Zend Debugger
From http://oreilly.com/flex/excerpts/enterprise-development-with-flex/selected-design-patterns.html
As the name singleton implies, only one instance of such a class can be instantiated, which makes such classes useful if you’d like to create some kinds of global repositories of the data so that various objects of your application can access them. In Chapter 1 , you saw examples of their use by various architectural Flex frameworks. For example, ModelLocator from Cairngorm provides a repository for the data that was retrieved by delegates so that the views can properly display it. But to get access to the data stored in this singleton, your application class has to first get a hold of this singleton:
var model: AppModelLocator = AppModelLocator.getInstance();
After this is done, you can access the data stored in various properties of the object to which the variable model refers.
If you need a Cairngorm singleton that can communicate with the server side, write the following code:
service = ServiceLocator.getInstance().getHTTPService( 'loadEmployeesService');
Pretty soon, your application code gets polluted with similar lines of code that try to get a reference to one of the singletons.
Here’s the idea. Why not just use a singleton that already exists in any Flex application instead of introducing new ones? This is a Flex Application object that’s always there for you because it is part of the Flex framework. Thus you can be fairly sure that there is only one instance of it.
The problem is that the Application class was not created as dynamic, and you need to either extend it to act as a singleton with specific properties, or make it dynamic to be able to add to the application singleton any properties dynamically. Example 2-1 ’s dynamic class DynamicApplication is a subclass of the Flex class Application. It implements a Dictionary that allows you to register your services with the application.
Example 2-1. DynamicApplication class
package com.farata.core{
import flash.utils.Dictionary;
import mx.core.Application;
public dynamic class DynamicApplication extends Application implements
IApplicationFacade{
public function DynamicApplication(){
super();
}
public static var services:Dictionary = new Dictionary();
// Consider using getter and setter if you need to override behavior
// but a workaround with "static" problem in Flex
public function getService(name:String) : Object {
return services[name];
}
public function addService(name:String,value: Object): void {
services[name] = value;
}
public function removeService(name:String) : void {
delete services[name];
}
public function getServices() : Dictionary {
return services;
}
}
}
This singleton class implements the IApplicationFacadeinterface (Example 2-2), which defines the methods to add, remove, and get a reference to the objects that are required by your application. The main reason to use the IApplicationFacade interface here is that when you typecast an Application with this interface in your code, you get Flash Builder’s “intellisense” support and compile-time error checking.
Example 2-2. IApplicationFacade interface
package com.farata.core {
import flash.utils.Dictionary;
public interface IApplicationFacade {
function getService(name:String) : Object ;
function addService(name:String,value:Object):void ;
function removeService(name:String) : void ;
function getServices() : Dictionary ;
}
}
Note that the test program shown in Example 2-3 is no longer a regular <mx:Applica tion>, but rather an instance of the dynamic class shown in Example 2-1 and is located in thePatterns_lib project. Upon application startup, it calls the function addAllServices(), which dynamically adds myModel and myServices properties to the application object. Now any other object from the application can access this global repository just by accessing DynamicApplication.servicesfollowed by the property you are trying to reach. This is illustrated in the functions getData() and setData() used in Example 2-3 .
Example 2-3. The application Singleton.mxml
<?xml version="1.0" encoding="utf-8"?>
<fx:DynamicApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
xmlns:fx="http://www.faratasystems.com/2009/components"
creationComplete="addAllServices();">
<mx:Script>
<![CDATA[
import com.farata.core.DynamicApplication;
import mx.core.Application;
// Add required services to the Application object. // For illustration purposes, we'll add myModel and // myServices
private function addAllServices() :void {
// Add the model repository to the application object
DynamicApplication.services["myModel"]= new Object();
// Add the services to the application object
DynamicApplication.services["myServices"] = new Object();
}
private function getData(serviceName:String, key:Object):Object{
return DynamicApplication.services[serviceName][key];
}
private function setData(serviceName:String, key:Object, value:String):void{
DynamicApplication.services[serviceName][key]= new String(value);
}
]]>
</mx:Script>
<!--Adding values to myModel -->
<mx:Button label="Add to myModel" x="193" y="59"
click="setData('myModel',key.text, value.text)"/>
<mx:Label x="14" y="42" text="Key" fontWeight="bold"/>
<mx:Label x="14" y="14" fontWeight="bold" fontSize="14">
<mx:text>
Add one or more key/value pairs to the object MyModel
</mx:text>
</mx:Label>
<mx:Label x="91" y="42" text="Value" fontWeight="bold"/>
<mx:TextInput x="8" y="59" id="key" width="75"/>
<mx:TextInput x="89" y="59" id="value" width="96"/>
<!--Retrieving the value from a Singleton. -->
<mx:Button label="Show the value" x="8" y="122" click=
"retrievedValue.text=getData('myModel', key.text) as String"/>
<mx:Label x="135" y="121" width="95" id="retrievedValue" fontWeight="bold"
fontSize="15"/>
<mx:Label x="10" y="94" fontWeight="bold" fontSize="14">
<mx:text>
Retrieve and display the value from MyModel bykey
</mx:text>
</mx:Label>
</fx:DynamicApplication>
As Figure 2-1 shows, this application displays a window in which a user can add any key/value pairs to the myModelobject located in the singleton DynamicApplication. Then you can access them by key by clicking on the button labeled “Show the value.”
The point of this exercise was to show how you can use a somewhat modified Flex Application object to create a global repository (a singleton) without the need to implement the singleton design pattern on your own.
发表评论
-
js调用flash的方法时报错:Error calling method on NPObject!
2012-12-27 15:53 3140如题; uncaught exception: Error ... -
AIR 2.6 NativeProcess is not supported
2012-03-28 11:46 1879使用Flex AIR2.6开发桌面程序,添加程序自己重启或启动 ... -
AIR application killed when check camera device
2011-07-25 19:16 746I met this problem and spen ... -
UIComponent中的parentDocument和parent
2011-06-26 17:26 1579ParentAndParentDocument.mxml ... -
[Forward]How to compile CSS file in Flash Builder
2010-12-10 00:39 839It's so easy.Step1. Right click ... -
[Forward]Selected Design Patterns - Asynchronous Token
2010-12-05 00:32 960Consider an enterprise applic ... -
[Forward]Selected Design Patterns - Data Transfer Object
2010-12-05 00:18 938Data transfer objects are als ... -
[Forward]Selected Design Patterns - Mediator
2010-12-04 23:51 916Almost any complex screen of ... -
[Forward]Selected Design Patterns - Proxy
2010-12-04 23:20 774A proxy is an object that re ... -
Debugging with Google Chrome and Flash Player 10.1
2010-09-19 11:53 1035http://polygeek.com/2780_flex_d ... -
If the porgram is already running, close it before attempting to run.
2010-08-24 17:29 1753Launch Failed! If the program ... -
DataGrid选不中行
2010-07-15 17:01 777I have noticed a strange behavi ... -
Avoiding duplicate session detected errors in LCDS (and BlazeDS)
2010-07-01 18:34 1445Original article path:http://ww ... -
Server.Processing.DuplicateSessionDetected
2010-07-01 16:58 1949Earlier i faced one issue ... -
USING FLEX 3 ADVANCEDDATAGRID IN FLASHDEVELOP
2010-05-14 16:54 1352Those of you attempting to u ... -
[转记]AS3中的continue和break新用法
2010-04-06 20:25 2728AS3中的continue(continue [label]) ... -
BlazeDS & Hibernate lazy loading in n-tier arhitecture
2010-03-01 10:42 901原文链接:http://forum.springsource. ... -
连接FMS,Hello Hailin
2009-11-13 18:50 848FMS 虽然已经升级到3.5版本, 但是仍然是支持AS1.5, ... -
从Flex3到Flex4的转变一览(样式应用、主题等)
2009-11-13 11:43 4587文章转载http://devilkirin.iteye.com ... -
关于flex事件的讲解
2009-09-20 17:03 1061文章来自:http://www.riachina.com/sh ...
相关推荐
这个压缩包“java-design-patterns-master”显然是一个专注于Java设计模式的学习资源,旨在帮助开发者深入理解和应用这些模式。下面我们将详细探讨Java设计模式及其在实际开发中的应用。 1. **单例模式(Singleton...
Kasampalis -- Mastering Python Design Patterns -- 2015 -- code.7z
JAVA设计模式一直是JAVA最考验内功的技术点。有句话说的很好,理解吃透设计模式概念如果是3分的难度,那么自己能写出来就是10分的...java-design-patterns-master是github上比较优秀的设计模式项目,这里与大家分享!
Design Patterns - Elements of Reusable Object-Oriented Software [English] Design Patterns 英文版 带书签 解压密码:123456
head first design patterns-head first 设计模式的英文原版;高清英文原版,非扫描
Design Patterns-Elements of Reusable Object-Oriented Software 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源...
这是单例设计模式的基本示例。 您将在此仓库中找到两个示例。 首先是线程安全的单例,其次不是。...Thread 2 instance is : com.caslaner.designpatterns.singleton.service.CacheUnSynchronized@35c
《Head First设计模式》是一本深受开发者喜爱的设计模式入门书籍,其官方源码库"Head-First-Design-Patterns-master.zip"包含了书中所讲解的各种设计模式的实际代码示例,旨在帮助读者更深入地理解并应用这些模式。...
https://github.com/kamranahmedse/design-patterns-for-humans 中文翻译,实例修改位JAVA代码
With Learning JavaScript Design Patterns, you’ll learn how to write beautiful, structured, and maintainable JavaScript by applying classical and modern design patterns to the language. If you want to...
"Laracasts - design-patterns-in-php.torrent"则可能是一个BT种子文件,用于通过BitTorrent协议下载整个课程的大型数据包,这通常包括所有视频讲座和其他相关文件。 在课程"设计模式在PHP中"中,你可能会学到以下...
Design Patterns-Elements of Reusable Object-Oriented Software + 源代碼
b站李建忠讲的C/C+设计模式的ppt, ... 设计模式(Design pattern)是一套被反复使用、多数人知晓的、经过分类编目的、代码设计经验的总结。使用设计模式是为了可重用代码、让代码更容易被他人理解、保证代码可靠性。
《Pro-Objective-C-Design-Patterns-for-iOS》是一本专注于在iOS平台上利用Objective-C语言实现设计模式的专业书籍。书中旨在帮助已经有一定Cocoa开发基础的开发者,通过掌握设计模式的实践应用,提升软件开发的生产...
Leverage the power of Python design patterns to solve real-world problems in software architecture and design
《大话设计模式》C++实现-design-patterns-cpp
Design the core areas of the Azure Execution Model Work with storage and data management Create a health endpoint monitoring pattern Automate early detection of anomalies Identify and secure ...