Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— 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,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)Internationalization module Saves development time by automatically generating code to implement an interface or create a proxy class (used by the GWT RPC module)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.PopupPanel The use of 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 the user.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.GWT.create(Class)

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. The PopupPanel 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:GWT.create(Class)

9

10 After the GWT compiler runs It prunes out any unused code If your application references the PopupPanel class – the compiler will create a separate JavaScript output file for each browser, each containing only one of the implementations: PopupImpl, PopupImplIE6 or PopupImplM ozilla. – 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.


Download ppt "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."

Similar presentations


Ads by Google