Assignment # 6 (Principles Of OOP) - Rozeenaa/LearningJava GitHub Wiki
The Object Oriented Programming is constructed over four major principles. Encapsulation , Data Abstraction , Polymorphism and Inheritance.
1. Encapsulation:
Encapsulation means that the internal representation of an object is generally hidden from view outside of the objects defination. Typically , only the object's own methods can directly inspect or manipulate its fields.
Encapsulation is the hiding of data implementation by restricting access to accessors and mutators.
An accessors is a method that is used to ask an object about itself. In OOP, these are usualy in the form of properties, which have a get method , which is an accessor method. However, accessor methods are not restricted to properties and can be any public method that gives information about the state of the object.
A Mutator is public method that is used to modify the state of an object, while hidding the implementation of exactly how the data gets modified. It's the set method that lets the caller modify the member data behind the scenes.
A benefit of fencopsulation is that it can reduce system complexity.
2. Abstraction:
Data abstraction and encapsulation are closely tied together, because a simple defination of data abstraction is the development of classes, objects, types in terms of their interfaces and functionality, instead of their implementation details. Abstraction denote a model, a view, or some other focused representation for an actual item.
"An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of object and thus provide crispy defined conceptual boundaries, relative to the perspective of the viewre."
In short, data abstraction is nothing more than the implementation of an object that contains the same essential properties and actions we can find in the original object we are representing.
3. Inheritance:
Inheritance is a way to reuse code of existing objects, or to establish as subtype from an existing object, or both, depending upon programmming language support. In classical inheritance where objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, parent classes or ancestor classes. The resulting classes are known as derived classes, subclasses or child classes. The relationship of classes through inheritance gives rise to a hierarchy.
4. Polymorphism
Polymorphism mean one name, many forms. Polymorphism manifests itself by having multiple methods all with the same name, but slightly diffrent functionality.
There are two basic types of polymorphism .
Overriding also called run-time polymorphism. For method overloading, the compiler determines which method will be executed, and this dicision is made when the code gets compiled.
Overloading, which is referred to as compile-time polymorphism. Method will be used for overriding is determined at runtime based on the dynamic type of an object.