Previous: , Up: Interface Interop [Contents]


4.3.1.2 Building Interfaces Around Objects

A consequence of the previous section is that users of GNU ease.js can continue to use strongly typed interfaces even if the objects they are interfacing with do not support ease.js’ interfaces. Consider, for example, a system that uses XMLHttpRequest:

 // modeled around XMLHttpRequest
 var HttpRequest = Interface(
 {
 abort: [],
 open: [ 'method', 'url', 'async', 'user', 'password' ],
 send: [],
 } );
 var FooApi = Class(
 {
 __construct: function( httpreq )
 {
 if ( !( Class.isA( HttpRequest, httpreq ) ) )
 {
 throw TypeError( "Expecting HttpRequest" );
 }
 // ...
 }
 } );
 FooApi( new XMLHttpRequest() ); // okay

Figure 4.6: Building an interface around needed functionality of XMLHttpRequest

This feature permits runtime polymorphism with preemptive failure instead of inconsistently requiring duck typing for external objects, but interfaces for objects handled through ease.js.

Part of the GNU Project

Copyright © 2011, 2012, 2013, 2014, 2015, 2016 Free Software Foundation, Inc.

"GNU Inside!" Page Fold licensed under CC-BY-SA 2.0; incorporates "A Big GNU Head".

The source code of this website is available in the website branch of the Git repository.

Authored by Mike Gerwitz

AltStyle によって変換されたページ (->オリジナル) /