Wednesday, 9 December 2015

61_OOPS_IN_PHP_2

• Access SPECIFIER specify the level of access that the outside world (i.e. other class objects, external functions and global level code) have on the class methods and class data members. Access specifies can either be public, private or protected.


• Now it’s time to give the answer why this access specifies are needed, so the reasons about this access specified is, used as a key component of Encapsulation and Data Hiding discuss latter. By using either of the access specifies mentioned above i.e. public, private or protected you can hide or show the internals of your class to the outside world.


• All the access specifies are declare in the class which is one kind of structure where you can declare your variables and methods with the use of above access specifies, so that variable will perform the necessary task.


PRIVATE


• The one be the best example of the private is we are interested to hide our password from outer world.


• Now how this access specifies is declared.





• If you are interested to hide the data member or member functions to the outside world (Means class). This means that only the class that defines such data member and member functions have access them.


• Now to access the class member, we must require the object of the class; with the use of the object we are able to used the methods and variable of the class.





• If we write the below syntax then it will show me the error, reason is that the $name is the declare as private means we are not able to use them outside the class.





PUBLIC


• Now let’s understand the meaning of public in the class, if we declare our variable as public then it will allow using that variable outside the class.





• If we write the code as shown below then it will execute successfully reason is that our variable declare as public, so if we write this sentences outside the class then it will execute successfully and give us the perfect and real output.





PROTECTED


• A protected access specifies is mainly used with inheritance. A data member or member function declared as protected will be accessed by its class and its base class but not from the outside world (i.e. rest of the script). We can also say that a protected data member is public for the class that declares it and it’s child class; but is private for the rest of the program (outside world).





• With the use above discussion we got the idea about how we can declare our variable in the class, now lets understand what is the meaning class, class is specific place where you can declare your number of variable and methods with the use of private, public and protected.


• Now if we interested to use the class member we must required the object, without the object we are not able to access the class member (VARIABLE & METHODS).


• Benefits of oops liked, reusability, refactoring, extensible, maintenance, efficiency.


Encapsulation


• Encapsulation is the procedure of covering up of data and functions into a single unit.


• Encapsulation (also information hiding) consists of separating the external aspects of an object which are accessible to other objects, from the internal implementation details of the object, which are hidden from other objects.


Polymorphism


• Object could be any type. A discrete object can have discrete property and methods which work separately to other object.


• However a set of object could be derived from parent object and retain some properties of the parent class. This process is called polymorphism. An object could be morphed into several other objects retaining some of its behavior.


Inheritance


• The key process of deriving a new object by extending another object is called inheritance. When you inherit an object from another object, the subclass derives all the properties and methods of the parent(SUPERCLASS)


• A subclass can then process each method of super class anyway (Which is called overloading).



No comments:

Post a Comment