Inheritance
- When one object acquires all the properties and behaviors of a parent object.
- It provides code reusability.
- It is used to achieve runtime polymorphism
Polymorphism
- If one task is performed in different ways, it is known as polymorphism.
- To convince the customer differently, to draw something, for example shape, triangle, rectangle, etc...
- In Java we use method overloading and method overriding to achieve polymorphism.
- Another example would be how to speak something, a cat meows, a dog barks, a bird chirps.
Abstraction
- Hiding internal details and showing functionality is abstraction.
- For example, we don't know the internal processing.
- We use abstract class and interface to achieve abstraction.
Encapsulation
Binding(or wrapping) code and data together into a single unit are known as encapsulation.
- For example, a capsule it is wrapped with different medicines.
- A java class is the example of encapsulation.
- Java bean is the fully encapsulated class because all the data members are private here.
Coupling
- Coupling refers to the knowledge or information or dependency of another class.
- It arises when classes are aware of each other.
- If a class has the details of another class, there is a strong coupling.
- In java, we use private, protected, and public modifiers to display the visibility level of a class, method and filed.
- You can use interfaces for the weaker coupling because there is no concrete implementation.
Association
Association represents the relationship between the objects. Here, one object can be associated with one object or many objects. There can be four types of association between the objects.
- one to one
- one to many
- many to one
- many to many
- For example, one country can have one prime minister (one to one.)
- A prime minister can have many ministers (one to many)
- Also, many MP's can have one prime minister (many to one)
- Many ministers can have many departments (many to many).
Aggregation
Aggregation is a way to achieve Association.
- Aggregation represents the relationship where one object contains other objects as part of its state.
- It represents the weak relationship between objects.
- It is also termed as a has=a relationship in Java.
- Like, inheritance represents the is-a relationship.
- It is another way to reuse objects.
Composition
The composition is also a way to achieve Association.
The Composition represents the relationship where one object contains other objects as a part of its state.
There is a strong relationship between the containing object and the dependent object.
It is the state where containing objects do have an independent existence.
If you delete the parent object, all the child objects will be deleted automatically.
The Composition represents the relationship where one object contains other objects as a part of its state.
There is a strong relationship between the containing object and the dependent object.
It is the state where containing objects do have an independent existence.
If you delete the parent object, all the child objects will be deleted automatically.
Advantanges of OOPs over Procedure Oriented Programming language
1. OOps make development and maintenance easier, where as, in a procedure oriented programming language, it is not easy to manage if the code grows as project size increases.
2. OOPs provides data hiding, where as in a procedure oriented programming, language global data can be accessed from anywhere.
3. OOPs provides the ability to simulate real world event much more effectively. We can provide the solution of real world problem if we are using the object oriented programming language.
2. OOPs provides data hiding, where as in a procedure oriented programming, language global data can be accessed from anywhere.
3. OOPs provides the ability to simulate real world event much more effectively. We can provide the solution of real world problem if we are using the object oriented programming language.
What is the difference between an object oriented programming language and an object based programming language
Object based programming language follows all the features of OOPs. except Inheritance.
JavaScript and BVScript are examples of Object Based Language.
JavaScript and BVScript are examples of Object Based Language.