Please enable JavaScript.
Coggle requires JavaScript to display documents.
OOP diagram (Encapsulation (Default (It is not a keyword, if any access…
OOP diagram
Encapsulation
The implementation and state of each object are privately held inside a defined boundary, or class. Other objects do not have access to this class or the authority to make changes but are only able to call a list of public functions, or methods. This characteristic of data hiding provides greater program security and avoids unintended data corruption.
Private
The access scope of the private members are restricted to the class scope only, means private members are not accessible or available from the another class.
Public
The access modifier has widest scope mean the public class members can be accessed from any class despite package of the classes and relationship.
Protected
The access level or scope of the protected class members are restricted to within the current or same package and from another package if and only if a class is inherited by the class from another package.
Default
- It is not a keyword, if any access modifiers keyword is not defined then it will be considered as default.
- The access scope of the default members are restricted to the current or same package(folder).
- The default members are not accessible or available from classes that are not present in the same package.
Abstraction
Objects only reveal internal mechanisms that are relevant for the use of other objects, hiding any unnecessary implementation code. This concept helps developers make changes and additions over time more easily.
Abstract Class
A class which is declared “abstract” is called as an abstract class. It can have abstract methods as well as concrete methods. A normal class cannot have abstract methods.
Abstract Method
A method without a body is known as an Abstract Method. It must be declared in an abstract class. The abstract method will never be final because the abstract class must implement all the abstract methods.
Rules
-
If a class is using an abstract method they must be declared abstract. The opposite cannot be true. This means that an abstract class does not necessarily have an abstract method.
If a regular class extends an abstract class, then that class must implement all the abstract methods of the abstract parent
-
-
Polymorphism
Objects are allowed to take on more than one form depending on the context. The program will determine which meaning or usage is necessary for each execution of that object, cutting down on the need to duplicate code.
Method Overriding
Rules
- The method signature i.e. method name, parameter list and return type have to match exactly.
- The overridden method can widen the accessibility but not narrow it, i.e. if it is private in the base class, the child class can make it public but not vice versa.
Method Overloading
Method overloading is in the same class, where more than one method have the same name but different signatures.
Inheritance
Relationships and subclasses between objects can be assigned, allowing developers to reuse a common logic while still maintaining a unique hierarchy. This property of OOP forces a more thorough data analysis, reduces development time and ensures a higher level of accuracy.
- In Java, when an "Is-A" relationship exists between two classes we use Inheritance.
- The parent class is termed super class and the inherited class is the sub class.
- The keyword "extend" is used by the sub class to inherit the features of super class.
- Inheritance is important since it leads to reusability of code.