Flex + Java 中小型项目的代码结构研究
<!---->1.?<!---->系统性能和系统可维护性上的平衡(Value Object lazy load)
<!---->2.?<!---->开发效率和代码可读性上的平衡(Command and CommandManager)
<!---->3.?<!---->如何让Flex调用服务端的Service(AMF3,Remote Object)
<!---->4.?<!---->使用Cache Framework提升我们的性能
<!---->一.??<!---->系统性能和系统可维护性上的平衡(Value Object lazyload)
<!---->A.?????<!---->传输规范的数据结构。这时候必然会带上一些冗余数据,如显示用户清单时传输的UserVO,而UserVO里同时也包含了标志这个用户部门的DepartmentVO,这时就会带来不必要的数据传输,如果显示的用户清单有100条,那么这100个UserVO里面的DepartmentVO必然会带来不小的数据冗余。
<!---->B.?????<!---->只在网络上传输必要的数据。这时有两种方法可以做到,设计一个UserListVO,里面包含user name和department name这两样field,然后在BusinessLogic里组装这个UserListVO。但这种方法显然有个大的缺点,这个VO或对应的业务逻辑代码不可以共用,因为不同的地方会有不同的业务需求,比如有一个模块中会要显示用户的年龄。另一个方法就是,使用规范的数据结构,但只为这些数据结构中必要的栏位设值,如上面所说的,可以只为userVO.departmentVO.name设值,但其它栏位保持null,显然,这个VO的共用性也不好,因为我没法知道这个VO里面的栏位是否已经被设值了。
<!---->二.???<!---->开发效率和代码可读性上的平衡(Command andCommandManager)
<!---->1.?<!---->创建一个CairngormEvent,并在这个Event里要有一个userId:Number的field。
<!---->2.?<!---->创建一个Command,这个Command要实现两个接口,ICommand和IResponder。
<!---->3.?<!---->创建一个FrontController来建立Event和Command的关连。
<!---->三.??<!---->如何让Flex调用服务端的Service(AMF3, Remote Object)
<!---->1.?<!---->在service.xml里添加配置项<mx:RemoteObject/>
<!---->2.?<!---->创建Delegate.as,并为RemoteObject添加对应的方法(这里需要为每个服务端对象都创建对应的Delegate和方法,工作量不但不小,而且很烦哦)
ServiceFactory.getService(ServiceFactory.USER_BIZ)
.callService(ServiceFactory.USER_BIZ_INSERT,[newVO], this.result);
<!---->四.??<!---->使用Cache Framework提升我们的性能
[Bindable]public var departmentVO : DepartmentVO;//todo//why cannot use "get departmentVO()", and bind userVO.departmentVO.name to datagridpublic function getDepartmentVO():DepartmentVO{var responder:LazyLoaderResponder;if(departmentVO == null && !isNaN(departmentId)){responder = new LazyLoaderResponder(this, "departmentVO"); ServiceFactory.getService(ServiceFactory.DEPARTMENT_BIZ).callServiceWithResponder(ServiceFactory.DEPARTMENT_BIZ_LOAD, [departmentId], responder);}return departmentVO;}[Bindable]public var departmentVO : DepartmentVO;//todo//why cannot use "get departmentVO()", and bind userVO.departmentVO.name to datagridpublic function getDepartmentVO():DepartmentVO{var responder:LazyLoaderResponder;if(departmentVO == null && !isNaN(departmentId)){responder = new LazyLoaderResponder(this, "departmentVO"); ServiceFactory.getService(ServiceFactory.DEPARTMENT_BIZ).callServiceWithResponder(ServiceFactory.DEPARTMENT_BIZ_LOAD, [departmentId], responder);}return departmentVO;}
首先感谢你分享思路,说实话,我也刚开始这方面的工作,还没有深入研究,如果有好的实践一定与大家分享。
It is impossible to use
"function getDepartmentVO():DepartmentVO "
to get the return DepartmentVO
Because you use Remote Object!
Generally the Sychronize way you can use
function getDepartmentVO():DepartmentVO {
dosmothing;
return DepartmentVO ;
}
But ASycronize way you cant do this
it should be :
[Bindable]
var returnVO:DepartmentVO;
function getDepartmentVO():void{
myservice.getVOByRemoterObject();
the RemoteObject.addListener("getDepartment", theDepartmentVOHandler);
}
function theDepartmentVOHandler(event Resultevent){
returnVO = event.casttoDepartmentVO;
}
it is impossible to getDepartmentVO() directly
[Bindable]public var departmentVO : DepartmentVO;//todo//why cannot use "get departmentVO()", and bind userVO.departmentVO.name to datagridpublic function getDepartmentVO():DepartmentVO{var responder:LazyLoaderResponder;if(departmentVO == null && !isNaN(departmentId)){responder = new LazyLoaderResponder(this, "departmentVO"); ServiceFactory.getService(ServiceFactory.DEPARTMENT_BIZ).callServiceWithResponder(ServiceFactory.DEPARTMENT_BIZ_LOAD, [departmentId], responder);}return departmentVO;}
首先感谢你分享思路,说实话,我也刚开始这方面的工作,还没有深入研究,如果有好的实践一定与大家分享。
It is impossible to use
"function getDepartmentVO():DepartmentVO "
to get the return DepartmentVO
Because you use Remote Object!
Generally the Sychronize way you can use
function getDepartmentVO():DepartmentVO {
dosmothing;
return DepartmentVO ;
}
But ASycronize way you cant do this
it should be :
[Bindable]
var returnVO:DepartmentVO;
function getDepartmentVO():void{
myservice.getVOByRemoterObject();
the RemoteObject.addListener("getDepartment", theDepartmentVOHandler);
}
function theDepartmentVOHandler(event Resultevent){
returnVO = event.casttoDepartmentVO;
}
it is impossible to getDepartmentVO() directly
Please take a look at following two lines
responder = new LazyLoaderResponder(this, "departmentVO"); ServiceFactory.getService(ServiceFactory.DEPARTMENT_BIZ).callServiceWithResponder(ServiceFactory.DEPARTMENT_BIZ_LOAD, [departmentId], responder);