Extends? Implements? Private, Public, Protected?
View Single Post
05-05-2008, 01:10 AM
Join Date: Nov 2007
Originally Posted by
Extension means that you inherit the properties and methods from a class, so that gives you access to the private methods, right?
Yes, extending a class means your child classes inherit all properties and methods. No, if they are declared private, then only the parent class has access to them. This is why I recommend to give them the protected visibility so derived classes can still have access to those properties. Note that even private properties are inherited, they're just not accessible.
Originally Posted by
Abstract... That sounds pointless to me. It allows for empty methods? Woopdie doo :/
Static? Meh, again, no use seen.
Actually, abstract classes are a very powerful way to implement what's known as polymorphism, or the ability to use different objects in the same way. This
Wikipedia article on Object Oriented programming
states that and more.
Think of abstract classes like this: you want to create an object that handles data storage. Period. The interface should be the same regardless of how the class stores data. So you can have an abstract class named 'DataHandler' with methods like 'putData' and 'getData', etc. You can derive this abstract class into a class that interacts with databases, or a class that stores and retrieves data from a flat file. These classes can be further derived into classes that specify what type of database, if the file is XML, JSON or regular text, etc. But the calling object will still use the same 'getData' and 'putData' methods, so it's totally flexible if you should want to switch how you store data.
Static method calls are essential in most OO programming; I use them everyday.
The bottom line; unless you plan on going all OO in your PHP code, or switch to Java or C#, all of this may not be relevant to you.
I reject your reality, and substitute my own.
The Following User Says Thank You to SOCK For This Useful Post:
View Public Profile
Send a private message to SOCK
Find More Posts by SOCK