JavaAbstraction-one of the most important feature of 4 pillars of OOPS

Abstraction-one of the most important feature of 4 pillars of OOPS

What is abstraction ?

Abstraction is the practice of hiding from the outside world the internal information of an application. To explain things in simple terms, abstraction is used. It’s used to establish a boundary between the client systems and the application.

This is

Real world example

Let ‘s take the first example of a vehicle that abstracts the internal information and reveals only those data to the driver that are important to the driver’s interaction with the vehicle. Like we are giving only break and accelerator, don’t give any internal working of it.

What are the different abstraction types?

There are two types of abstraction.

  1. Data Abstraction
  2. Process Abstraction

Data Abstraction It provides data abstraction where the object data is not accessible to the outside world. If required, some methods provide access to the objects’ data.

Process Abstraction

We don’t need to provide information on any of an object’s functions. It provides method isolation as we cover the internal implementation of the multiple functions involved in a user operation.

AirPlane is interface

package com.onurdesk.oop.abstraction;

public interface Airplane{
	
	void takeOff();
	void landing();
	String getFlightType();
		
}

PassengerPlan and FighterPlan are the implementation of Plan

package com.onurdesk.oop.abstraction;

public class FighterAirplane implements Airplane{
	
	private String flightType = "FighterPlan";

	@Override
	public void takeOff() {
		System.out.println("The Airplane is take off ");
		// TODO Auto-generated method stub
		
	}

	@Override
	public void landing() {

		System.out.println("The Airplane is landing ");
		
		// TODO Auto-generated method stub
		
	}

	@Override
	public String getFlightType() {
		// TODO Auto-generated method stub
		return this.getFlightType();
	
	}
}
package com.onurdesk.oop.abstraction;

public class PassengerAirplane implements Airplane{
	
	private String flightType = "PassengerPlan";

	@Override
	public void takeOff() {
		System.out.println("The plan is take off ");
		// TODO Auto-generated method stub
		
	}

	@Override
	public void landing() {

		System.out.println("The plan is landing off ");
		
		// TODO Auto-generated method stub
		
	}

	@Override
	public String getFlightType() {
		// TODO Auto-generated method stub
		return this.getFlightType();
	}
}
package com.onurdesk.oop.abstraction;

public class AirplaneTest {

	public static void main(String[] args) {
		
		Airplane plan1 = new PassengerAirplane();
		Airplane plan2 = new FighterAirplane();
		
		plan1.takeOff();
		plan1.landing();
		System.out.println(plan1.getFlightType());
		
		plan2.takeOff();
		plan2.landing();
		System.out.println(plan2.getFlightType());
		
	}
}

The client software knows only about the Airplane and the functions that are given by the schedule. The internal specifics of deployment are withheld from the client program.

Quiz

1. Identify basic abstractions of data and related processes in your kitchen. Justify these abstractions by demonstrating that these abstractions 
can help to handle the shift as specifications change.
2. Identify basic abstractions of data and related processes in your kitchen. Justify these abstractions by demonstrating that these abstractions 
can help to handle the shift as specifications change.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe Today

GET EXCLUSIVE FULL ACCESS TO PREMIUM CONTENT

Get unlimited access to our EXCLUSIVE Content and our archive of subscriber stories.

Exclusive content

Latest article

More article