What is Abstraction in OOPs? Java Abstract Class & Method

It is a technique used in designing computer software, hardware, and communications in which system or network components are isolated in layers so that changes can be made in one layer without affecting the others. Abstractions can prove useful when dealing with computer programs, because non-trivial properties of computer programs are essentially undecidable (see Rice’s theorem). As a consequence, automatic methods for deriving information on the behavior of computer programs either have to drop termination , soundness , or precision (they may answer “I don’t know” to some questions). In a simple program, this may aim to ensure that loops have single or obvious exit points and to have single exit points from functions and procedures. You could, for example, reuse the brewEspresso method when you want to support the CoffeeSelection.CAPPUCCINO. You would then just need to implement the required operations to heat the milk, call the brewEspresso method to get an espresso, and add it to the milk. Using the CoffeeMachine class is almost as easy as making your morning coffee.

abstraction in programming

Abstraction is one of the key concepts of object-oriented programming languages. Its main goal is to handle complexity by hiding unnecessary details from the user. That enables the user to implement more complex logic on top of the provided abstraction without understanding or even thinking about all the hidden complexity. You could say that this approach is highly computational, which forces the developer to focus mainly on individual tasks the machines must carry out. 3GLs are the first step toward allowing programmers to tackle larger and more diverse requirements, as they do when programming enterprise applications. While the first two generations of programming languages were highly machine-dependent, 3GLs, which are sometimes referred to as mid-level and sometimes high-level languages, can run on different machines, which is in and of itself a major innovation.

Code

You can implement the brewCoffee method without knowing any details about the grinding or brewing process. You just need to know how to instantiate the 2 classes and call the grind and brew methods. Someone else worried about that and created a coffee machine that now acts as an abstraction and hides all these details. You just interact with a simple interface that doesn’t require any knowledge about the internal implementation. For example, building an enterprise case management application with a high-code 4GL can take months. With a 3GL, it could take years, but with low-code, a developer can build an enterprise-grade application in weeks or even days.

Some other abstractions such as software design patterns and architectural styles remain invisible to a translator and operate only in the design of a system. The process of reorganizing common behavior from non-abstract classes into “abstract classes” using inheritance to abstract over sub-classes as seen in the object-oriented C++ and Java programming languages. As mentioned above, programming languages can be broken down into high-level languages and low-level languages. The first two generations consist of low-level languages, while the third through fifth generations are populated by high-level languages. Each successive generation represents an evolution toward using more natural language, which is accomplished by adding layers of abstraction.

Second-generation languages (2GL)

The UML specification language, for example, allows the definition of abstract classes, which in a waterfall project, remain abstract during the architecture and specification phase of the project. Some abstractions are designed to inter-operate with other abstractions – for example, a programming language may contain a foreign function interface for making calls to the lower-level language. The classes Grinder and BrewingUnit provide abstractions on their own. The Grinder abstracts the complexity of grinding the coffee and BrewingUnit hides the details of the brewing process. Using the concept of abstraction, you can hide all these decisions and processing steps within your CoffeeMachine class. If you want to keep it as simple as possible, you just need a constructor method that takes a Map of CoffeeBean objects to create a new CoffeeMachine object and a brewCoffee method that expects your CoffeeSelection and returns a Coffee object.

  • When you use a few functions from an outside library, you can see how the code is written and simply add your own function or class.
  • Example of different levels of abstractionEach box is a different level of abstraction.
  • The developer most likely doesn’t even know that the Grinder or BrewingUnit class exists.
  • The main purpose of abstraction is hiding the unnecessary details from the users.

Structured programming involves the splitting of complex program tasks into smaller pieces with clear flow-control and interfaces between components, with a reduction of the complexity potential for side-effects. Some abstractions try to limit the range of concepts a programmer needs to be aware of, by completely hiding the abstractions that they in turn are built on. The software engineer and writer Joel Spolsky has criticised these efforts by claiming that all abstractions are leaky – that they can never completely hide the details below; however, this does not negate the usefulness of abstraction. The hardware implements a model of computation that is interchangeable with others. The software is structured in architectures to enable humans to create the enormous systems by concentrating on a few issues at a time. These architectures are made of specific choices of abstractions. Greenspun’s Tenth Rule is an aphorism on how such an architecture is both inevitable and complex.

Generations of programming languages

Hiding the complexity, however, should not in any way negatively impact the power and versatility of the machine and its output. To the contrary, adding abstraction layers should result in more robust and useful outputs. Difference between Abstract Class and Interface An abstract class can have both abstract and non-abstract methods.

What are examples of abstract words?

Examples of abstract terms include love, success, freedom, good, moral, democracy, and any – ism (chauvinism, Communism, feminism, racism, sexism).

Though a 1GL program would be incredibly tedious to write, if it’s error-free, it would run very fast, as there would be no additional translation necessary from the coding language to the language the computer can process. The first half of the equation, however, is a story of ever-increasing abstraction. Each generation has brought a higher level of abstraction from low-level to high-level languages to bring more intuitive language into programming.

What is Abstraction in Programming – And Why is it Useful?

Abstraction in computer science is closely related to abstraction in mathematics due to their common focus on building abstractions as objects, but is also related to other notions of abstraction used in other fields such as art. The brewFilterCoffee and brewEspresso methods abstract the specific operations required to brew the coffee.

  • There is still a tremendous amount of art and skill involved in creating programs, even when most or all of the code has been abstracted away.
  • SimArch example of layered architecture for distributed simulation systems.
  • This is then duplicated billions of times to create modern CPUs.
  • The implementation of abstraction depends on the language-specific features and processes.
  • The applied physicists focus on the level of abstraction where components are created, with what materials, with the time to create them…
  • The uppermost level may feature a menu of typical end-user operations.
  • Various object-oriented programming languages offer similar facilities for abstraction, all to support a general strategy of polymorphism in object-oriented programming, which includes the substitution of one type for another in the same or similar role.

Article was published on: 10/20/22

Author: Viktor Nikolaev

Victor is a professional crypto investor and stockbroker, specializing in such areas as trading on the stock exchange, cryptov currencies, forex, stocks and bonds. In this blog he shares the secrets of trading, current currency indices, crypt currency rates and tells about the best forex brokers. If you have any questions, you can always contact nikolaev@forexaggregator.com

Leave a Reply