Abstract/Interface OOP Question

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

I'm trying to strengthen my knowledge in PHP OOP. What I don't understand is abstract, interface and other kinds of classes there are in PHP.

Could someone possibly list all of the possible classes I can have and describe them?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6251
  • Loc: Seattle, WA

Post 3+ Months Ago

An interface isn't a class; it's a set of function declarations (not definitions). A class that implements an interface is guaranteed to define all of the functions in the interface. Other classes then reference the interface rather than the underlying classes directly, which hides the details of implementation.

An abstract class is a class that cannot be instantiated (you can't create an object). You must create a subclass that extends the abstract class. Most often, the abstract class will contain some undefined member variables and methods, and it's up to the subclass to define them,

Also, theses are common OOP concepts; they aren't specific to PHP. PHP isn't a very good language to use for learning the principles of OOP, in my opinion, since it was never originally and object-oriented language.
  • Nightslyr
  • Proficient
  • Proficient
  • Nightslyr
  • Posts: 283

Post 3+ Months Ago

Both are used to facilitate polymorphism. Abstract classes and interfaces create is-a relationships. If a class implements a particular interface, or extends an abstract class, then an object of that class is also considered to be an instance of that interface or abstract class.

Unfortunately, since type doesn't matter much in PHP, you really don't get to see this in action much.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 143 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.