October 8th, 2012, 12:11 AM
The purpose of interfaces in OOP
Can someone explain the main purpose of interfaces in OOP.
Please explain in total moron language.
October 8th, 2012, 12:23 AM
Interfaces declare behavior without saying exactly how code accomplishes that. An interface for a database class can give functions like "get all the rows from a table matching some criteria" or "insert some values into a table" without having to care about the database system, extension, API, or how either of those functions actually work - so long as they do what the interface says they do.
It's very similar to an abstract class, except the class can provide some functionality which will probably need to exist (and it would be the same everywhere) while an interface cannot define any code whatsoever. So it's fairly common to make an interface for the functionality, then make an abstract class which implements parts of the interface, then make a real concrete class which fills in the parts that the abstract class couldn't.
October 8th, 2012, 05:11 AM
this has been discussed multiple times in this forum:
And haven't you asked the same question about a year ago?