Object-Oriented Programming System (OOPS) is the basic concept of many programming languages. It is a paradigm based on the object which contains methods and data. This concept is used to make programming a class and object model which behaves like a real-world scenario. In this article, we’ll learn about messages, aggregation, composition and abstract classes in the OOPS paradigm.
Message Passing: Message Passing in terms of computers is communication between processes. It is a form of communication used in object-oriented programming as well as parallel programming. Message passing in Java is like sending an object i.e. message from one thread to another thread. It is used when threads do not have shared memory and are unable to share monitors or semaphores or any other shared variables to communicate. The following are the main advantages of the message passing technique:
- This model is much easier to implement than the shared memory model.
- Implementing this model in order to build parallel hardware is much easier because it is quite tolerant of higher communication latencies.
In OOPs, there are many ways to implement the message passing technique like message passing through constructors, message passing through methods or by passing different values. The following is a simple implementation of the message passing technique by the values:
Int Value is : 101 Float Value is : 20.7
Aggregation: This is a form of association in a special way. Aggregation is strictly directional association (i.e.), one-way association and represents HAS-A relationship between the classes. Also, in aggregation, ending one of the classes between the two does not affect another class. It is often denoted as a weak association whereas composition is denoted as a strong association. In composition, the parent owns the child entity that means child entity will not exist without parent entity and also, child entity cannot be accessed directly. Whereas, in the association, the parent and child entity can exist independently. Let’s take an example to understand this concept. Lets take a student class and an Address class. The address class represents the student address. Since every student has an address, it has an has a relationship. However, the address is completely independent of student. If some student leaves the school or the college, he or she still has an address. This means that the address can survive independently without the student. Therefore, this is an aggregation. The following is an implementation of the above example:
Roll no: 96 Name: Utkarsh Street: 10 City: Delhi State: Delhi Country: India
Abstract Classes: Abstraction is a technique used in OOPS paradigm which shows only relevant details to the user rather than showing unnecessary information on the screen helping in reduction of the program complexity and efforts to understand. Every OOPS implemented language has a different kind of implementation but has the same concept of hiding irrelevant data. Abstract classes are one such way in java to implement the abstraction. In Java, abstract classes are declared using abstract keyword and can have abstract as well as normal methods but, normal classes cannot have abstract methods declared in it. Abstract classes either have a definition or they are implemented by the extended classes. Let’s take an example to understand why abstraction is implemented. In this example, we will create cars manufactured in a specific year. There can be many cars manufactured in a specific year. But the properties of cars doesn’t change. So, the name of the car here is abstract and the remaining properties are constant. The following is an implementation of the above example:
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Abstract Classes in Java
- C# | Abstract Classes
- Abstract Classes in Python
- Why Java Interfaces Cannot Have Constructor But Abstract Classes Can Have?
- Association, Composition and Aggregation in Java
- 3 Different ways to print Exception messages in Java
- Spring Boot | How to consume JSON messages using Apache Kafka
- Spring Boot | How to consume string messages using Apache Kafka
- Difference between Abstract Class and Interface in Java
- Difference between Abstract Class and Concrete Class in Java
- Difference between Final and Abstract in Java
- abstract keyword in java
- Scala | Abstract Type members
- Why can't static methods be abstract in Java?
- Why does PHP 5.2+ disallow abstract static class methods ?
- Abstract Methods in Java with Examples
- OOPS | Generalization as extension and restriction using Java
- Understanding OOPs and Abstraction using Real World Scenario
- OOPs | Object Oriented Design
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.