Extending Interfaces in c sharp

It is possible to extend an existing interface to add new methods or members, or to modify how existing members work.

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. 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.

interface ILoggedCompressible : ICompressible

{

void LogSavedBytes();

}

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 also ICompressible.

Objects of that type can be cast either to ILoggedCompressible or to ICompressible.

extends ICompressible to create ILoggedCompressible, and then casts the Document first to be of type IStorable, 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).

Example Extending interfaces
using System;


namespace InterfaceDemo

{

interface IStorable

{

void Read();

void Write(object obj);

int Status { get; set; }



}

// the Compressible interface is now the

// base for ILoggedCompressible

interface ICompressible

{

void Compress();

void Decompress();

}



// extend ICompressible to log the bytes saved

interface ILoggedCompressible : ICompressible

{

void LogSavedBytes();

}





// Document implements both interfaces
{

// the document constructor

public Document(string s)

{

Console.WriteLine("Creating document with: {0}", s);



}



// implement IStorable

public void Read()

{

Console.WriteLine(

"Implementing the Read Method for IStorable");

}



public void Write(object o)

{

Console.WriteLine(


"Implementing the Write Method for IStorable");


public class Document : IStorable, ILoggedCompressible


RELATED POST

SOFTWARE QUALITY ASSURANCE AND CONTROL

SOFTWARE QUALITY AND COST ASPECT

STABLE PROCESS OF SOFTWARE TESTING

STABLE PROCESS OF SOFTWARE TESTING PART TWO


DEFECTS IN SOFTWARE TESTING

REDUCTION OF DEFECTS IN SOFTWARE TESTING

SOFTWARE TESTING AND EFFECTING FACTORS

SCOPE OF SOFTWARE TESTING

TESTING LIFE CYCLE PART ONE

TESTING LIFE CYCLE PART TWO

TESTING LIFE CYCLE PART THREE

SOFTWARE TESTING AND CONSTRAINTS WITH IN IT

TESTING CONSTRAINTS PART TWO

LIFE CYCLE TESTING

TEST METRICS

Independent Software Testing

Test Process

Testing verification and validation

Functional and structural testing

Static and dynamic testing

V model testing

Eleven steps of V model testing

Structural testing

Execution testing technique

Recovery Testing technique


Operation testing technique


Compliance software testing technique

Security testing technique
Here i am adding the further topics list on software testing subject and the topics may be scattered and you can find under different groups.

MAJOR SYSTEM FAILURES IN THE HISTORY

WHAT IS A SOFTWARE BUG ?

ROLE OF A TESTER

SOFTWARE TESTING INTRODUCTION PART ONE

TESTING INTRODUCTION PART TWO

TESTING INTRODUCTION PART THREE

TESTING INTRODUCTIONS PART FOUR

SOFTWARE TESTING FUNDAMENTALS

SOFTWARE TESTING FUNDAMENTALS PART TWO

SOFTWARE TESTING FUNDAMENTALS PART THREE


No comments:

Post a Comment