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

  1. 云栖社区>
  2. 博客>
  3. 正文

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

橘子红了呐 2017-11-11 00:55:00 浏览1071

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



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.





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

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




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.













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。如果你的设备是单个用户使用,并且运行主应用程序,那么就考虑使用kiosk模式。记住,Windows Mobile不支持kiosk模式,所以你必须使用Windows CE




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.





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






+ 关注