1 / 10

Coding Basics - Deferred Binding

Coding Basics - Deferred Binding. Deferred Binding. is a feature of the GWT compiler works by generating many versions of code at compile time, only one version needs to be loaded by a particular client during bootstrapping at runtime.

effie
Download Presentation

Coding Basics - Deferred Binding

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Coding Basics - Deferred Binding

  2. Deferred Binding • is a feature of the GWT compiler • works by generating many versions of code at compile time, • only one version needs to be loaded by a particular client during bootstrapping at runtime. • Each version is generated on a per browser basis, along with any other axis that your application defines or uses. • For example, if you were to internationalize your application using GWT's Internationalization module, • the GWT compiler would generate various versions of your application per browser environment, • such as "Firefox in English", "Firefox in French", "Internet Explorer in English", etc... • As a result, the deployed JavaScript code is compact and quicker to download than hand coded JavaScript, containing only the code and resources it needs for a particular browser environment.

  3. Deferred Binding Benefits • Reduces the size of the generated JavaScript code that a client will need to download by only including the code needed to run a particular browser/locale instance (used by the Internationalization module) • Saves development time by automatically generating code to implement an interface or create a proxy class (used by the GWT RPC module) • Since the implementations are pre-bound at compile time, there is no run-time penalty to look up an implementation in a data structure as with dynamic binding or using virtual functions.

  4. Defining Deferred Binding Rules • There are two ways in which types can be replaced via deferred binding: • Replacement: A type is replaced with another depending on a set of configurable rules. • We only cover this • Code generation: A type is substituted by the result of invoking a code generator at compile time.

  5. Deferred Binding Using Replacement • Replacement means overriding the implementation of one java class with another that is determined at compile time. • For example, this technique is used to conditionalize the implementation of some widgets, such as the PopupPanel. • The use of <inherits> for the PopupPanel class is shown in the previous section describing the deferred binding rules.

  6. Popup.gwt.xml • The actual replacement rules are specified in Popup.gwt.xml, as shown below:

  7. Popup.gwt.xml • These directives tell the GWT compiler to swap out the PoupImpl class code with different class implementations according to the theuser.agent property. • ThePopup.gwt.xml file specifies a default implementation for the PopupImpl class, an overide for the Mozilla browser (PopupImplMozilla is substituted for PopupImpl), and an override for Internet Explorer version 6 (PopupImplIE6 is substituted for PopupImpl). • Note that PopupImpl class or its derived classes cannot be instantiated directly. Instead, the PopupPanel class is used and the GWT.create(Class) technique is used under the hood to instruct the compiler to use deferred binding.

  8. Example Class Hierarchy using Replacement • To see how this is used when designing a widget, we will examine the case of the PopupPanel widget further. • ThePopupPanel class implements the user visible API and contains logic that is common to all browsers. It also instantiates the proper implementation specific logic using the GWT.create(Class) as follows:

  9. After the GWT compiler runs • It prunes out any unused code • If your application references thePopupPanelclass • the compiler will create a separate JavaScript output file for each browser, • each containing only one of the implementations: PopupImpl,PopupImplIE6 or PopupImplMozilla. • This means that each browser only downloads the implementation it needs, • thus reducing the size of the output JavaScript code and minimizing the time needed to download your application from the server.

More Related