Refactoring – a new feature in the Visual C# 2.0 IDE
CoderSource.net
Refactoring – a new feature in the Visual C# 2.0 IDE - Article by muskad202
Level: BeginnerType: Article
Rating: Page: 3 of 4

Date: 4/23/2006 12:00:00 AM

Environment: Windows, Visual Studio .Net 2005

Refactoring – a new feature in the Visual C# 2.0 IDE

Implementing Interfaces

Assume you have an interface containing say, 30 functions.

You now want to write a class that implements this interface, but don't have the enthusiasm to implement all 30 functions (you just want to implement a couple for them for quick testing). What do you do? You cant just implement the ones you're interested in - the compiler will never let you hear the end of it). Fortunately, the C# 2005 IDE gives you a way out. Here's what you do - declare your class that implements the interface. Then, right click on the interface name, and choose the option "Implement interface", and voila! The stubs are created for you.

You must have seen that there's also an "Implement Interface Explicitly" option. What does that do? Well, that just puts the Interface name in front of the function name or property name which is being implemented - because, there might be situations where a class is implementing two interfaces, and both the interfaces have a function foo(), and in your class, you might want to provide separate implementations for foo() depending on the interface through which it is invoked. In that case, you will need to inform the compiler as to which implementation is for which interface. The image below should make things clearer:

As you can see, the IsUsernameValid() function definitions are now prefixed by the Interface names. (The above code was generated by right clicking on the interface name and choosing "Implement Interface Explicitly".

1 2 3 4

You Can Rate this Article, if you are Logged In      
 

More Links from CoderSource.net:

 
Refer to a Friend:

Your Details:

Name:     e-mail:

Friend Details:

Name:    e-mail:    


MENU
Home
MFC 
C++
.Net
WIN32
Programming
Forum
My Articles
Add to Google
Add to My Yahoo!
Welcome to Codersource.Net Login | Register | Faq  

SEARCH
Google
 

NOTES:


Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

© Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us