print barcode with vb.net Extending Interfaces in C#

Creating USS Code 128 in C# Extending Interfaces

Extending Interfaces
Code 128B Encoder In Visual C#.NET
Using Barcode generator for .NET Control to generate, create Code 128A image in .NET applications.
www.OnBarcode.com
USS Code 128 Recognizer In C#
Using Barcode reader for .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
You can extend an existing interface to add new methods or members. For example, you might extend ICompressible with a new interface, ILoggedCompressible, which extends the original interface with methods to keep track of the bytes saved.
Paint Linear Barcode In Visual C#
Using Barcode generation for Visual Studio .NET Control to generate, create Linear Barcode image in Visual Studio .NET applications.
www.OnBarcode.com
Code-39 Maker In C#.NET
Using Barcode creator for Visual Studio .NET Control to generate, create Code39 image in Visual Studio .NET applications.
www.OnBarcode.com
|
UPC-A Supplement 2 Drawer In C#.NET
Using Barcode creation for .NET framework Control to generate, create UPC-A Supplement 5 image in Visual Studio .NET applications.
www.OnBarcode.com
Data Matrix 2d Barcode Creation In Visual C#
Using Barcode generator for Visual Studio .NET Control to generate, create Data Matrix 2d barcode image in Visual Studio .NET applications.
www.OnBarcode.com
13: Interfaces
Drawing Code 128 Code Set C In Visual C#.NET
Using Barcode drawer for .NET framework Control to generate, create Code 128B image in VS .NET applications.
www.OnBarcode.com
ITF14 Maker In C#.NET
Using Barcode drawer for Visual Studio .NET Control to generate, create ITF-14 image in .NET framework applications.
www.OnBarcode.com
One such method might be called LogSavedBytes( ). The following code creates a new interface named ILoggedCompressible that is identical to ICompressible except that it adds the method LogSavedBytes:
Drawing ANSI/AIM Code 128 In Objective-C
Using Barcode creator for iPad Control to generate, create Code-128 image in iPad applications.
www.OnBarcode.com
Painting Code 128B In None
Using Barcode drawer for Software Control to generate, create Code 128 Code Set B image in Software applications.
www.OnBarcode.com
interface ILoggedCompressible : ICompressible { void LogSavedBytes( ); }
UPC - 13 Decoder In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
UCC-128 Creation In None
Using Barcode generator for Font Control to generate, create EAN / UCC - 13 image in Font applications.
www.OnBarcode.com
Classes are now free to implement either ICompressible or ILoggedCompressible, depending on whether they need the additional functionality. If a class does implement ILoggedCompressible, it must implement all the methods of both ILoggedCompressible and ICompressible. Objects of that type can be cast either to ILoggedCompressible or to ICompressible. Example 13-4 extends ICompressible to create ILoggedCompressible, and then casts the Document first to be of type IStorable and then to be of type ILoggedCompressible. Finally, the example casts the Document object to ICompressible. This last cast is safe because any object that implements ILoggedCompressible must also have implemented ICompressible (the former is a superset of the latter). This is the same logic that says you can cast any object of a derived type to an object of a base type (that is, if Student derives from Human, then all Students are Human, even though not all Humans are Students).
QR Code Generation In None
Using Barcode generation for Online Control to generate, create QR Code image in Online applications.
www.OnBarcode.com
Generating UCC-128 In Java
Using Barcode encoder for Java Control to generate, create UCC - 12 image in Java applications.
www.OnBarcode.com
using using using using System; System.Collections.Generic; System.Linq; System.Text;
Printing Matrix 2D Barcode In VS .NET
Using Barcode printer for VS .NET Control to generate, create 2D Barcode image in .NET applications.
www.OnBarcode.com
PDF-417 2d Barcode Creation In Java
Using Barcode creation for Java Control to generate, create PDF-417 2d barcode image in Java applications.
www.OnBarcode.com
namespace Example_13_4_ _ _ _Extending_Interfaces { interface ICompressible { void Compress( ); void Decompress( ); } // extend ICompressible to log the bytes saved interface ILoggedCompressible : ICompressible { void LogSavedBytes( ); } public class Document : ILoggedCompressible { public Document(string s) {
Barcode Maker In None
Using Barcode encoder for Office Word Control to generate, create Barcode image in Office Word applications.
www.OnBarcode.com
Denso QR Bar Code Drawer In Objective-C
Using Barcode creator for iPhone Control to generate, create QR Code JIS X 0510 image in iPhone applications.
www.OnBarcode.com
Extending Interfaces |
Data Matrix Creator In None
Using Barcode printer for Word Control to generate, create Data Matrix ECC200 image in Word applications.
www.OnBarcode.com
PDF 417 Drawer In None
Using Barcode maker for Online Control to generate, create PDF 417 image in Online applications.
www.OnBarcode.com
Console.WriteLine("Creating document with: {0}", s); } #region public void Compress( ) { Console.WriteLine("Executing Compress"); } public void Decompress( ) { Console.WriteLine("Executing Decompress"); } public void LogSavedBytes( ) { Console.WriteLine("Executing LogSavedBytes"); } #endregion //ILoggedCompressible } class Tester { public void Run( ) { Document doc = new Document("Test Document"); ILoggedCompressible myLoggedCompressible = doc as ILoggedCompressible; if (myLoggedCompressible != null) { Console.Write("\nCalling both ICompressible and "); Console.WriteLine("ILoggedCompressible methods..."); myLoggedCompressible.Compress( ); myLoggedCompressible.LogSavedBytes( ); } else { Console.WriteLine("Something went wrong! Not ILoggedCompressible"); } } static void Main( ) { Tester t = new Tester( ); t.Run( ); }
|
13: Interfaces
} }
The output looks like this:
Creating document with: Test Document Calling both ICompressible and ILoggedCompressible methods... Executing Compress Executing LogSavedBytes
Example 13-4 starts by creating the ILoggedCompressible interface, which extends the ICompressible interface:
// extend ICompressible to log the bytes saved interface ILoggedCompressible : ICompressible { void LogSavedBytes( ); }
Notice that the syntax for extending an interface is the same as that for deriving from a class. This extended interface defines only one new method (LogSavedBytes( )), but any class implementing this interface must also implement the base interface (ICompressible) and all its members. (In this sense, it is reasonable to say that an ILoggedCompressible object is an ICompressible object.)
Combining Interfaces
You can also create new interfaces by combining existing interfaces and optionally adding new methods or properties. For example, you might decide to combine the definitions of IStorable and ICompressible into a new interface called IStorableCompressible. This interface would combine the methods of each of the other two interfaces, but would also add a new method, LogOriginalSize( ), to store the original size of the precompressed item:
interface IStorableCompressible : IStorable, ILoggedCompressible { void LogOriginalSize( ); }
Having created this interface, you can now modify Document to implement IStorableCompressible:
public class Document : IStorableCompressible
You now can cast the Document object to any of the four interfaces you ve created so far:
IStorable storableDoc = doc as IStorable; ILoggedCompressible logCompressDoc = doc as ILoggedCompressible;
Copyright © OnBarcode.com . All rights reserved.