#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,959
    Rep Power
    173

    The purpose of interfaces in OOP


    Hello;

    Can someone explain the main purpose of interfaces in OOP.

    Please explain in total moron language.

    Thanks
  2. #2
  3. Subconscious Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    15,531
    Rep Power
    9565
    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.
  4. #3
  5. No Profile Picture
    Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    57
    Rep Power
    0
    Hi,

    this has been discussed multiple times in this forum:
    forums.devshed.com/php-development-5/questioning-the-use-of-abstract-classes-vs-regular-classes-929822.html

    And haven't you asked the same question about a year ago?
    forums.devshed.com/php-development-5/the-puspose-of-abstract-classes-851690.html

IMN logo majestic logo threadwatch logo seochat tools logo