Client classes in .NET

Printer PDF417 in .NET Client classes

Client classes
Print PDF-417 2d Barcode In .NET Framework
Using Barcode generator for ASP.NET Control to generate, create PDF 417 image in ASP.NET applications.
www.OnBarcode.com
EAN-13 Supplement 5 Generation In Visual Studio .NET
Using Barcode generation for ASP.NET Control to generate, create GS1 - 13 image in ASP.NET applications.
www.OnBarcode.com
In this section, we ll discuss how the Microsoft Ajax Library upgrades a JavaScript constructor to a client class. Throughout the book, we ll use the term client class to refer to a class created in JavaScript with the Microsoft Ajax Library. From a developer s point of view, the process is straightforward: All you have to do is add a single statement after the declaration of the constructor. Listing 3.4 illustrates this concept by showing how to create a Pet class starting from a Pet constructor.
Drawing Data Matrix ECC200 In Visual Studio .NET
Using Barcode creator for ASP.NET Control to generate, create Data Matrix 2d barcode image in ASP.NET applications.
www.OnBarcode.com
Creating USS-128 In .NET
Using Barcode creation for ASP.NET Control to generate, create EAN / UCC - 14 image in ASP.NET applications.
www.OnBarcode.com
Listing 3.4 A Pet class defined with the Microsoft Ajax Library
Linear Barcode Printer In VS .NET
Using Barcode generator for ASP.NET Control to generate, create 1D Barcode image in ASP.NET applications.
www.OnBarcode.com
Drawing UCC - 12 In .NET
Using Barcode creation for ASP.NET Control to generate, create UPC A image in ASP.NET applications.
www.OnBarcode.com
function Pet() { this._name; this._age; } Pet.prototype = { speak : function() { throw Error.notImplemented(); } } Pet.registerClass('Pet');
Make USS Code 128 In .NET
Using Barcode creator for ASP.NET Control to generate, create Code 128 Code Set C image in ASP.NET applications.
www.OnBarcode.com
Create GTIN - 14 In .NET Framework
Using Barcode drawer for ASP.NET Control to generate, create Case Code image in ASP.NET applications.
www.OnBarcode.com
JavaScript for Ajax developers
Encode PDF-417 2d Barcode In C#.NET
Using Barcode maker for .NET Control to generate, create PDF-417 2d barcode image in .NET framework applications.
www.OnBarcode.com
PDF 417 Encoder In Java
Using Barcode generation for Java Control to generate, create PDF417 image in Java applications.
www.OnBarcode.com
The last statement in listing 3.4 contains a call to the registerClass method. As we ll discuss shortly, this method is responsible for setting up the constructor to make it behave as a class. To recap, defining a client class is a three-step process:
Drawing Barcode In None
Using Barcode drawer for Software Control to generate, create Barcode image in Software applications.
www.OnBarcode.com
Generate UCC - 12 In Java
Using Barcode generator for BIRT Control to generate, create UPC-A Supplement 2 image in Eclipse BIRT applications.
www.OnBarcode.com
1 2 3
Drawing Code 3/9 In C#
Using Barcode printer for Visual Studio .NET Control to generate, create Code 3 of 9 image in .NET applications.
www.OnBarcode.com
PDF 417 Encoder In Java
Using Barcode maker for Java Control to generate, create PDF 417 image in Java applications.
www.OnBarcode.com
Declare the constructor, which declares the fields of the class. Fill the prototype object, which defines methods of the class. Add a call to registerClass, which upgrades the constructor to a client class.
GS1-128 Creation In None
Using Barcode generation for Office Excel Control to generate, create UCC.EAN - 128 image in Office Excel applications.
www.OnBarcode.com
GS1 DataBar Stacked Creator In VS .NET
Using Barcode printer for .NET Control to generate, create GS1 DataBar Expanded image in .NET applications.
www.OnBarcode.com
The registerClass method alone has the power to transform a simple JavaScript function into a client class. For this reason, it deserves some more attention.
Create Barcode In None
Using Barcode generator for Online Control to generate, create Barcode image in Online applications.
www.OnBarcode.com
UPC - 13 Generation In None
Using Barcode printer for Excel Control to generate, create EAN13 image in Office Excel applications.
www.OnBarcode.com
The registerClass method
Barcode Printer In Java
Using Barcode creation for BIRT Control to generate, create Barcode image in Eclipse BIRT applications.
www.OnBarcode.com
Barcode Scanner In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
As shown in listing 3.4, the call to registerClass is the only thing you have to add to a classic JavaScript function to make the Microsoft Ajax Library recognize it as a class. This method accomplishes three important tasks:
Registers the type name in the constructor Lets you specify a base class and takes care of automatically resolving the inheritance relationship Accepts one or multiple interface types that the client class will implement
You store the type name in the constructor so you can access this information at runtime. As you ll see in a moment, you usually declare classes by assigning an anonymous function to a namespaced variable. By doing so, there s no way to programmatically know the name of the variable and thus know the fully qualified type name. This is why you need to register the type name by storing it as a string in the constructor. Figure 3.2 shows how the Sys._Application class whose single instance is the Application object is registered in the MicrosoftAJAX.debug.js file.
Sys._Application.registerClass('Sys._Application', Sys.Component, Sys.IContainer);
Fully qualified name of the class
Base class
Interface
Figure 3.2 How the Sys._Application class is registered using the registerClass method. The class-registration process also lets you specify a parent class and the interfaces implemented by the class.
Classes in JavaScript
The figure shows the complete syntax for the registerClass method, which is called as a static method of the function you ll register as a class. Because the class can belong to a client namespace, you must pass a string with the fully qualified name of the class. This is the name of the class prefixed by the name of the containing namespace. In figure 3.2, Sys is the namespace that contains the _Application class. We ll discuss client namespaces in section 3.3.4. The second argument is a reference to the base class. In the Microsoft Ajax Library, a client class can have a single parent class. The advantage of specifying a base class in the call to registerClass is that you avoid writing the code needed to resolve the inheritance relationship. Instead, the library takes care of configuring instances of child classes automatically on your behalf. The subsequent arguments specify the list of interfaces implemented by the class. In figure 3.2, the _Application class implements a single interface called Sys.IContainer. In general, a client class can implement multiple interfaces.
How does it work
Because calls to registerClass are contained outside of any functions, they re executed by the client runtime when the code is parsed. As part of the registration process, various pieces of information are stored in the constructor. In debug mode, checks are performed to ensure that you re providing valid references to the base class and the interface types, and that you aren t registering the same class twice. Finally, the new type is tracked by adding it to an internal collection stored in the Sys object. This completes the registration process for a client class.
Once you create a class, you can take advantage of the other object-oriented constructs provided by the Microsoft Ajax Library. For example, you can expose the values of private fields through client properties.
Copyright © OnBarcode.com . All rights reserved.