I hve knowledge about interface and abstract class. but What is purpose of use in interface and abstract in Real Time Project.Please Give me Simple and Best Example. And What is meaning of Contract..As for Example Interface work as like contract.
Regards
Bvenkat Jeewesh
Loading

Sibeesh VenuPosted Jan 1, 2015, 1:14 PM
when you implemnt interface You are very much sure ,that the method in the interface is implemented in the class.
You can say Interface is a class which contain all unimplemented methods taht are implemented in Class that implement it.
Use:
Suppose you have a project with lot of classes and each class have no. of methods.
So , How you know which class implement perticuler methods.We make interface for each/some classes and implement these interfaces in that class.
Sai SherlekarPosted Oct 18, 2012, 3:51 AM
consider u r working on project where u need to add, edit, save in customer, invoice, cards etc.
so u can create interface with declaration of all add, edit ,save methods.
inherit interface in everywhere in ur project where u need to add, edit, save.
so u r strictly using same named method for add, edit, save in everywhere.
means u have created contract which should be follow everywhere to add, edit, save.
u can inherit more than one interface that is also major advantage.
Mahesh ChandPosted Jul 9, 2012, 4:56 PM
Roy SPosted Jul 9, 2012, 2:33 PM
But I have used an abstract class before and the way I see it, it's used to group a few common properties/methods together.
Say you're making a chess program and you're using 6 classes to represent the different chesspieces (pawn, rook, ..., king). These pieces are different from eachother in terms that they move different and some other differences, but they also have a lot in common. Like the location, if they moved already, color.
In this case it would be good if all the classes could inherit from another class containing those common properties. But creating a normal ChessPiece class would be weird in this case because it doesn't make sense that you can instantiate this class. The solution is to use a abstract class.
public abstract class Chesspiece
{
Point Location {get; set; }
bool HasMoved {get; set; }
Color Owner {get; set; }
}
public class Pawn : ChessPiece
{
//rest of class here
}
public class Rook : ChessPiece
{
//rest of class here
}
//rest of classes here