Application Architecture Guide 2.0 - CH 19 - Mobile Applications(4)

张宝
2023-12-01

本文翻译"Porting"、"Power"、"Synchronization"、"User Interface"和"Performance Considerations"部分。

 

Porting

Developers often want to port part or all of an existing application to a mobile device. Certain types of applications will be easier to port than others, and it is unlikely that you will be able to port the code directly without modification.

Consider the following guidelines when designing to port your existing application to a mobile device:

• If you are porting a rich client application from the desktop, rewrite the application in its entirety. Rich clients are rarely designed to suit a small screen size and limited memory and disk resources.

 If you are porting a Web application to a mobile device, consider rewriting the UI for the smaller screen size. Also, consider communication limitations and interface chattiness as these can translate into increased power usage and connection costs for the user.

 If you are porting an RIA client, research details to discover which code will port without modification. Consult the technology considerations section of this chapter for specific advice.

• Research and utilize tools to assist in porting. For example, Java-to-C++ convertors are available. When converting from Smartphone to Pocket PC code, Microsoft Visual Studio® will allow you to change the target platform and will provide warnings when you are using Smartphone-specific functionality. You can also link Visual Studio Desktop and Mobile projects to assist in knowing what is portable between the two projects.

• Do not assume that you can port custom controls as-is to a mobile application. Supported APIs, memory footprint, and UI behavior are different on a mobile device. Test the controls as early as possible so that you can plan to rewrite them or find an alternative if required.

移植

开发人员经常试图将部分或者整个现有的应用移植到移动设备上。有些比较容易,有些难度比较大。一般来说,直接移植代码,而不做任何修改,这种情况是不太可能的。将现有的应用移植到移动平台上时,考虑以下指导方针:

如果移植一个桌面平台的富客户端应用,那么就要全盘重新写代码。富客户端应用很少是为小屏幕、内存和磁盘资源受限的移动平台而设计的。

如果要移植一个网络应用到移动设备上,那就考虑重写UI部分,因为移动设备的界面很小。同时,必须考虑通信的限制和界面的繁琐,因为这些会转变成功耗和连接成本。

•如果移植一个富Internet应用客户端,那么就好好研究一下,哪些代码可以不加修改,就移植过来。请查看本章的technology considerations小节来获取更加具体的建议。

•研究并利用工具来帮助移植工作。例如,可以利用Java-to-C++的转换工具。将Smartphone平台的代码移植到Pocket PC上去时,Microsoft Visual Studio®可以允许你改变目标平台,在你使用Smartphone特有的功能时,会给出警告。你可以将Visual Studio的桌面项目和移动平台的项目进行关联,帮助你了解他们之间哪些是可以移植的。

•不要认为你可以将定制的控件原样地移植到移动平台上。移动平台所支持的API、内存大小和UI都是不一样的。尽早测试目标控件,这样你就可以打算重写或者寻找需要的替代方法。

 

Power

Power is the most limiting factor for a mobile device. All design decisions should at take into account how much power the device consumes and its effect on overall battery life. If you have a choice in devices, consider devices that can draw power from Universal Serial Bus (USB) or other types of data hookups. Research communication protocols for their power consumption.

Consider the following guidelines when designing for power consumption:

• To conserve battery life, do not update the UI while the application is in the background.

• Choose communication methods considering both power usage as well as network speed.

 Consider deferring nonessential wireless communications until the device is under external power.

 Implement power profiles to increase performance when the device is plugged into external power and not charging its battery.

 Design so that parts of the devices can be powered down when not in use, or when not required. Common examples are screen backlighting, hard drives, GPS functions, speakers, and wireless communications.

 Design services and communications to transfer the smallest number of bytes possible over the air. Choose protocols, design service interfaces, and batch communications with this goal in mind.

 If you are considering using the 3G hardware communications protocol, consider that while it is significantly faster, it also currently uses much more power than its predecessors, such as the Edge protocol. When you are using 3G, be sure to communicate in batched bursts and to shut down communication at times when it is not needed.

功耗

对于一个移动设备来说,电量是最受制约的一个因素。所有的设计决策都必须考虑设备将耗费多少电量以及它对电池的寿命将产生多大的影响。如果允许的话,你可以选择那些能够从USB或其他类型的数据连接线取电的设备。同时还要考虑通信协议的耗电情况。

在设计功耗的时候,考虑以下指导方针:

•为了节约电池电量,当应用程序在后台运行时,不要更新UI

在选择通信方式时,兼顾耗电和网络速度。

考虑推迟不必要的无线通信,直到设备由外部供电时才进行。

当设备插入外部供电接口,而不对电池进行充电时,要考察电压的分布以提高性能。

在设备不使用或者不需要时,能够使得设备的部分停止工作。通用的例子有背景灯,磁盘驱动器,GPS模块,话筒和无线通信。

通过空中接口传送数据时,设计合理的通信和服务来传送最少的数据量。特别是在选择协议,设计服务接口,进行通信批处理时要牢记这一点。

•如果你选择使用3G通信协议,与之前的EDGE协议相比,在速度增快的同时,要考虑他耗费了更多的能量。在使用3G的时候,最好使用批处理的突发通信,在不需要时将他关闭。

 

Synchronization

Consider whether you want to support over-the-air synchronization, cradled synchronization, or both. Because synchronization will often involve sensitive data, consider how to secure your synchronization data, especially when synchronizing over the air. Design your synchronization to handle connection interruptions gracefully, either by canceling the operation or by allowing it to resume when a connection becomes available. Merge replication allows both upload-only and bidirectional synchronization and is a good choice for infrastructures utilizing newer versions of SQL Server. Consider the Microsoft Sync Framework as it can provide robust synchronization services in a wide variety of situations.

Consider the following guidelines when designing synchronization:

• Design for recovery when synchronization is reset, and decide how to manage synchronization conflicts.

• If you must support bidirectional synchronization to SQL Server, consider using merge replication synchronization. Remember that merge synchronization will synchronize all of the data in the merge set, which may require additional network bandwidth and can impact performance.

 If your users must synchronize data when away from the office, consider including over-the-air synchronization in your design.

 If your users will be synchronizing with a host PC, consider including cradled synchronization in your design.

• Consider store-and-forward synchronization using WCF rather than e-mail or SMS (text message), as WCF guarantees delivery and works well in a partially connected scenario.

同步

考虑你是否需要空中接口同步、插座同步,或者是两者都需要。因为同步经常涉及到敏感数据,所以要保护好你的同步数据,特别是通过空中接口同步时更是如此。设计你的同步策略时,要处理连接中断的情况,解决方法可以是取消此次操作,或者是当连接可用时继续同步。合并复制允许上传和双向的同步操作,对于具有更新版本的SQL Server的设备来说,确实是一个不错的选择。考虑使用Microsoft Sync Framework,因为他能够在很多情况下,提供强健的同步服务。在设计同步策略时,考虑以下指导方针:

•在同步操作复位时,考虑恢复设置,同时还要处理如何管理同步冲突。

如果你必须支持和SQL Server的双向同步,那么考虑使用合并复制方式的同步。记住,合并同步操作会同步所有合并集中的数据,它需要额外的网络带宽,同时会影响应用程序性能。

当你的用户需要在离开办公室的条件下同步数据,那么在你的设计中考虑空中接口同步。

•如果你的用户要和主机同步,那么在你的设计中考虑插座同步。

•考虑使用WCF来进行存储转发式的同步,而非电子邮件或者是短信,因为WCF能够确保数据传送,并且在部分连接的情况下, 也能很好工作。

 

User Interface

When designing the UI for a mobile application, do not try to adapt or reuse the UI from a desktop application. Design your device UI so that it is as simple as possible, and designed specifically for pen-based input and limited data entry capabilities as appropriate. Consider the fact that your mobile application will run in full-screen mode and will only be able to display a single window at a time. Therefore, blocking operations will prevent the user from interacting with the application. Consider the various screen sizes and orientations of your target devices when designing your application UI.

Consider the following guidelines when designing the UI for your mobile application:

• Design considering that a person’s hand can block a touch-screen UI during input with a stylus or finger. For example, place menu bars at the bottom of the screen, expanding options upwards.

• Design for a single-window, full-screen UI. If your device will be a single-user device running only the main application, consider using kiosk mode. Keep in mind that Windows Mobile does not support a kiosk mode, so you will need to use Windows CE.

 Consider input from various sources such as stylus, keypad, and touch. For example, accommodate touch-screen input by making buttons large enough, and lay out controls so that the UI is usable using a finger or stylus for input. Design for various screen sizes and orientations.

• Give the user visual indication of blocking operations; for example, an hourglass cursor.

用户接口

在为移动应用设计UI时,不要尝试将一个桌面应用的UI稍加改变就重用到移动设备上。要将你的设备UI设计得尽量简单,并且要为基于触笔的输入和有限的数据获取能力而特殊考虑。要考虑你的应用程序会在全屏模式下运行,同时只能显示一个窗口。因此,这种操作会限制用户和应用程序的交互。在设计应用程序UI时,考虑目标设备的多种屏幕规格和方向。

在设计移动应用程序的UI时,考虑以下指导方针:

•在设计时,要考虑人手有可能在使用触笔或者指尖输入时,阻塞触摸屏UI。例如,将菜单栏放置在屏幕的底部,来扩展选项。

设计单窗口、全屏的UI。如果你的设备是单个用户使用,并且运行主应用程序,那么就考虑使用kiosk模式。记住,Windows Mobile不支持kiosk模式,所以你必须使用Windows CE

•考虑使用多种手段来采集数据,包括触笔、键盘和触摸。例如,将屏幕按钮调整的足够大,来适应触摸屏输入。将控件布置好,使得UI能够使用手指或者触笔来获取输入。同时,在设计时,考虑多种屏幕尺寸和方向。

•在程序运行时,如果占用了很长的时间,就要给用户阻塞的提示,比如使用沙漏光标。

 

Performance Considerations

Design your mobile application with device hardware and performance constraints in mind. Designing for a mobile device requires that you consider limited CPU speed, reduced memory and storage, narrow bandwidth and high latency connections, and limited battery life.

Consider the following guidelines when designing your performance strategy:

• Design configurable options to allow the maximum use of device capabilities. Allow users to turn off features they do not require in order to save power.

• To optimize for mobile device resource constraints, consider using lazy initialization.

 Consider limited memory resources and optimize your application to use the minimum amount of memory. When memory is low, the system may release cached intermediate language (IL) code to reduce its own memory footprint, return to interpreted mode, and thus slow overall execution.

• Consider using programming shortcuts as opposed to following pure programming practices that can inflate code size and memory consumption. For example, examine the cost of using pure object-oriented practices such as abstract base classes and repeated object encapsulation.

• Consider power consumption when using the device CPU, wireless communication, screen, or other power-consuming resources while on battery power. Balance performance with power consumption.

性能考虑

在设计你的移动应用程序的时候,要牢记设备硬件和性能的约束。包括有限的CPU速度,较小的存储空间,较低的网络带宽,较大的网络时延,以及受限的电池电量。

在设计性能策略的时候,考虑以下指导方针:

•设计可配置的选项来最大化地利用设备。允许用户关闭某些不需要的特性来节省用电。

针对移动设备资源受限的情况进行优化,考虑使用lazy initialization

•考虑受限的内存资源,优化应用程序,使用最少的内存。当内存低时,系统会释放缓存的IL代码来降低自身的内存使用,转为原来的模式,因此减缓了应用程序的整体执行速度。

•考虑使用捷径编程方式,而非纯粹的编程实践,因为它会增加代码量和内存消耗。例如,检查使用诸如抽象基类和二次对象封装的纯面向对象实践的方法。

•在使用设备的CPU、无线通信、屏幕或者其他耗电的资源时,考虑功耗情况。要在性能和功耗之间找到平衡点。



本文转自施炯博客园博客,原文链接:http://www.cnblogs.com/dearsj001/archive/2009/01/19/1378188.html,如需转载请自行联系原作者

 类似资料: