Abstraction by Parameterization and specification both are important methods in Java. We do this in hope of simplifying our analysis by separating attributes and details implementation for user requirements by showing the essential part to the user and hiding certain details for the various purposes like security, maintenance, etc.
- Abstractions help us in many ways like an easy way to arrange code.
- It also helps in decomposing big steps into smaller steps.
- It is useful for suppresses details and simplifying interaction.
- Abstraction plays an important role in improving the maintenance part of the project.
Basically abstraction is a method to provide simplicity by hiding all the mechanisms behind them. For example when someone calls you so you see on your screen that xyz is calling you with a green icon to receive and red icon with a reject option and some messaging option but, what you do not see is the all the backend mechanism that how someone is calling you how by tapping on-screen icon you can receive/reject or text someone how it’s going to connect to caller all the things. This way abstraction makes things simple.
Fee :1000 Hello! Ashish your roll_no is :12345
Methods of Abstraction :
- Abstraction by Parameterization.
- Abstraction by Specification.
Abstraction by Parameterization :
It abstracts from the identity of the data by replacing them with parameters.
x % 2 = 0
It describes a computation that when we divide a number x to 2 then the remainder is equal to zero which we use for finding that given number x is even or not.
x : int(x % 2 == 0)(y)
It is identical in meaning to
y % 2==0
In more familiar notation, we might denote the previous expression by the following expression given below.
Abstraction by Specification:
It abstracts from the implementation details (how the module is implemented) to the behavior users can depend on (what the module does). It isolates modules from one another’s implementations.
It allows us to abstract from the computation described by the body of a procedure to the end that procedure was designed to accomplish. We do this by associating with each other procedure a specification of its intended effect and then considering the meaning of a procedure call to be based on this specification rather than on the procedure’s body.
In this program, you will see how you can write the logic for a user like if the user wants only input any number and just to know whether a given number is odd or even the logic of the program is given below to check the even and odd for any user input number.
Input : 11 Output : Odd Input : 52 Output : Even
Enter an Integer number: 78 Entered number is even
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.