Blog

What are the adapters? What are the benefits of using them?

Mar 06, 2009 | English | By Crysfel | 3 Comments | Leer en Español

The Adapter pattern is used to allow classes to work together when normally could not because of incompatible interfaces, by providing its interface to clients while using the original interface.

What are the adapters? What are the benefits of using them?
Author: Crysfel

I'm a software developer with 6+ years of experience, when I'm not developing software I may be writing a tutorial, you can follow me on twitter

Libraries

We can be thankful that Ext JS was created as an extension to the library YUI and because its structure is well designed; because of this we can execute Ext JS over other libraries without a problem.

The implementations that now exist of this pattern (Adapter) are actually for the jQuery library, Prototype and YUI, also Ext JS has its own library which is called Ext-base. We can find the adapters in the following path ext-2.2/adapter.

Installation

To install one of these libraries we need to import it to the document immediately after importing the adapter and at the end, we need to import the Ext JS framework. Here’s an example on how to install jQuery.

<script type="text/javascript" src="../ext-2.2/adapter/jquery/jquery.js"></script>
<script type="text/javascript" src="../ext-2.2/adapter/jquery/ext-jquery-adapter.js"></script>
<script type="text/javascript" src="../ext-2.2/ext-all.js"></script>

Even though we can use any of the libraries we talked about before, we can only have one Adapter “linked” to a library.

Tests

To test if the jQuery library has been installed successfully we need to write jQuery code and execute it. We can test the jQuery installation when we change the event onReady of Ext JS following the jQuery style.

$(function(){
         $(document.body).css('background-color','#ccc');
         var win = new Ext.Window({
                   title:'Hello world',
                   width:400,
                   height:300,
                   minimizable:true,
                   maximizable:true
         });
         win.show();
});

One more test you can do is to change the background color of the body. You can do this with jQuery very easy, you just need to add the following line inside the event ready.

$(document.body).css('background-color','#333');

Conclusions

As you can see, it is very easy to install libraries that we want to use and we won’t see any difference because Ext JS behavior will be the same with any of these libraries.

During the rest of the course we will use the library Ext-base, since is the Ext JS owns library, but everyone can use the library of your choice or the best you know.

3 Responses to “What are the adapters? What are the benefits of using them?”

  • Jon Jan 14, 2010

    I have been using EXT Js for a while and am not sure what you mean by the adapter pattern. If you could put more detail in your post, i.e What the adapter pattern is and how its used by the Ext Js library it would be a useful read!

  • Tereza Feb 17, 2010

    As Jon wrote on 1.14.10, I would like to know: (1) if I wish to use TWO libraries, e.g., jQuery and Prototype, would that be possible? (2) As I understand what you wrote, I could only apply one adapter to each of the two libraries; only one adapter can be used for jQuery and only one adapter can with Prototype. (3) Also, could you let me know if these adapters will still work with the new 3.0 release(s)?

    • Crysfel Feb 19, 2010

      Hi Tereza.

      (1) if I wish to use TWO libraries, e.g., jQuery and Prototype, would that be possible? Yes! you can use anything you like.

      (2) As I understand what you wrote, I could only apply one adapter to each of the two libraries; only one adapter can be used for jQuery and only one adapter can with Prototype. Thats true, you can use the jQuery adapter and also import any other library such as prototype, mootools, jQuery and so on.

      (3) Also, could you let me know if these adapters will still work with the new 3.0 release(s)? of course! :)

Leave a Reply







Updates

RSS

Subscribe to our feeds to receive updates of our newest posts and free tutorials.

Site search

Maybe we have what you need, would you like to search first?

Donations

Would you buy me a cup of coffee? I am sharing my knowledge and time with you, help this project grow. Thank you!