In the implementation shown so far, the implementing class (Document) creates a member method with the same signature and return type as the method detailed in the interface. It is not necessary to explicitly state that this is an implementation of an interface; this is understood by the compiler implicitly.
What happens, however, if the class implements two interfaces, each of which has a method with the same signature? This might happen if the class implements interfaces defined by two different organizations or even two different programmers. The next example creates two interfaces: IStorable and ITalk. The latter implements a Read() method that reads a book aloud. Unfortunately, this conflicts with the Read() method in IStorable.
Because both IStorable and ITalk have a Read() method, the implementing Document class must use explicit implementation for at least one of the methods. With explicit implementation, the implementing class (Document) explicitly identifies the interface for the method:
void ITalk.Read()
Marking the Read() method as a member of the ITalk interface resolves the conflict between the identical Read() methods. There are some additional aspects you should keep in mind.
First, the explicit implementation method cannot have an access modifier:
void ITalk.Read()
This method is implicitly public. In fact, a method declared through explicit implementation cannot be declared with the abstract, virtual, override, or new keywords.
Most importantly, you cannot access the explicitly implemented method through the object itself. When you write:
theDoc.Read();
the compiler assumes you mean the implicitly implemented interface for IStorable. The only way to access an explicitly implemented interface is through a cast to the interface:
ITalk itDoc = theDoc as ITalk;
if (itDoc != null)
{
itDoc.Read();
Note that there is no need to use explicit implementation with the other method of ITalk:
Because there is no conflict, this can be declared as usual.
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