Why do we need interfaces?

Answer Posted / shivacharan

Reason1: In C# Multiple inheritence concept will be
implemented by Interfaces.
Reason2: When multiple ppl are working on one sigle
project, if they need to use some common functionality (for
example initializing the variables for thier modules)
instead of writing their own function name (like init,
initialize, setup etc etc) if we can write one single
function name (lets say initialize) then this function can
be implemented by any user who derives. That's it.

public interface IInitialize
{
void InitializeVar();
}
public classs Box:IInitialize
{
void InitializeVar()
{
//initializion of variables goes here
}
public classs Rectangle:IInitialize
{
void InitializeVar()
{
//initializion of variables goes here
}

this wil avoid all the confusion

Is This Answer Correct ?    23 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Differentiate between object pooling and connection pooling in c#?

539


What is the difference between ienumerable and iqueryable?

442


Describe an abstract class?

555


What is the difference between constant and readonly in c#?

431


How does return work in c#?

506






Can we write class inside a class in c#?

541


What is data binding with example?

493


Is it possible to inherit multiple interfaces?

539


Are arraylist faster or arrays?

484


What are fields in c#?

496


What is variable in c#?

510


Can I get the name of a type at runtime?

529


What is get set in c#?

558


What is session management in c#?

526


How do you use nullable?

499