Interface Programming tool A Concept

Interface is technique or concept which is used to add set of behavior or functionality to be mandatory. When we derive into class then class has to implement each thing that is in Interface. Something like making skeleton and then giving different look and behavior using that skeleton. Decoupling of object and  its implementation is possible because of interface.

Lets say you create interface of Cycle

Interface ICycle
{
void Handle(); 
void Wheels(); 
}

Inheriting class

class AtlasCycle: ICycle
{
void ResizableHandle()
{...
}
void fourDiaWheels()
{....
}
}

 

Above cycle skeleton can be used to derive any brand of bicycle with different feature values.

  • Interface has by default all fields, properties and methods Public. But you can have internally private and use it appropriately inside interface.
  • One which is public has to be implemented in inheriting class So it better than having base class.
  • Class can inherit as many as interfaces So structures can also use interfaces.
  • Interface does not have implementation only declarations.
  • It is highly used to design architecture. So it is architecture job to define what to be exposed and what not to client.

Happy Programming..

Number of View :971
  1. No comments yet.

SetPageWidth
Content Protected Using Blog Protector By: PcDrome.

Mahol Dot Org is Stephen Fry proof thanks to caching by WP Super Cache