Abstraction in Java

Abstraction

Abstraction on the other hand, can be explained as the capability to use the same interface for different objects. It involves the facility to define objects that represent abstract "actors" that can perform work, report on and change their state, and "communicate" with other objects in the system. Different implementations of the same interface can exist. Details are hidden by encapsulation.

To explain you about abstraction in java we can take three different entities (People in real world).
You: As a user you know how to start a washing machine. We just need to press a button and all other operations behind the scene are happening and are abstracted from user.
Now you are facing some problem with your machine when you are pressing start button it is not turning on there might be some major issue with your hardware which needs to be corrected. Then you call local mechanic to check the problem.
Local Mechanic: Our local mechanic knows some of the implementations of starting machine. He can open machine and check some wires and connections etc which means Local Mechanic knows some of the implementations of machine.
Now the situation arrived where we have to call washing machine manufacturing company service center and ask them for service of machine. They will send an expert to check the problem.
Expert: Since our expert (Designer of the machine) mechanic knows all the operations of our machine, he we repair it fast and will give you resolution of your problem. So in short Expert Entity knows all the implementations of the machine.
The machine's operation is completely abstracted from you and it is partially implemented to Local Mechanic and fully implemented to Expert. So you are an abstract class having only abstract methods, Local Mechanic has extended You(Since he is also an ordinary user) and he implemented some of the methods and last our expert extending Local Mechanic and implementing all the methods.
Also in terms of complexity "Whenever abstraction decreases, complexity increases"(Since our Expert Entity has very less abstraction, his complexity of work also increases)
In Java, garbage collection is also a best example for explaining abstraction.

If you still have any question you can reach me any time through email (jigyasu2010@hotmail.com)

Comments

Popular posts from this blog

How Method Overloading Helping in Java - Part 9

Design Patterns -- part 1

Access Modifiers in java