Some OOP Facts

Some OOP concepts

  • The main difference between OOP and functional programming is that the data and code are bundled together into one entity, which is known as an object.
  • During the execution of an object’s method, a special variable called $this is automatically defined, which denotes a reference to the object itself.
  • if a parent class declares a member as public, the inheriting child class must also declare it as public. Otherwise, the child would not have an is-a relationship with the parent, which means that anything you can do with the parent can also be done with the child.
  • When no access modifier is given for a method, public is used as the default.
  • You can define any number of methods as abstract, but once at least one method of a class is defined as abstract, the entire class needs to be declared as abstract, too.
  • In PHP, a method is either abstract (without code) or it’s fully defined.
  • PHP chose interfaces as an alternative to multiple inheritance.
  • An interface is declared similar to a class but only includes function prototypes (without implementation) and constants.
  • Note: Interfaces are always considered to be public; therefore, you can’t specify access modifiers for the method prototypes in the interface’s declaration.
  • There are times where you might want to make sure that a method cannot be re-implemented in its derived classes. For this purpose, PHP supports the final access modifier for methods that declares the method as the final version, which can’t be overridden.
  • Once a constant is defined, it can never be changed or undefined.
Advertisements

I like to hear from you about this !!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s