[JAVA] Summary of "abstract interface differences"

――The conclusion is as follows.

  1. abstract was used to save memory. However, the degree of freedom was so high that it triggered the provision of an interface.
  2. The interface was created to provide polymorphism (the one that implements ArrayList or LinkedList).
  3. The interface default was created to address Moore's Law.

How abstract came to be provided

First, I will explain the inheritance function from the basic history. (I'm sorry if you know it.)

In the olden days programming had little commercial value and had only small developments. From there, it became a large-scale development, and there was a problem that we wanted to make large-scale code easier to read and also lacked memory. So, by trying to save memory, I want reusability or abstraction! Thats how its going to be.

(Reconfirming the meaning of abstraction) For example, when we explain to others "baseball, soccer, tennis, etc. are fun!", In a word, "sports are fun!"

In the old days, programming did not have the power (abstraction) to put together such overlapping meanings. That's where object-oriented (Java) abstracts, which can also express parent classes (abstractions), came into play. (There was no interface at that time.)

The abstract was so flexible that it was hard to read. Both the method (function) and the global variable (state) came out, and it was something that I did not understand intuitively. Well, I could still use it.

How the interface came to be provided

At one point, there was a request for object-oriented development using abstract. I want to make it with polymorphism. And I want to make it easier to read by setting a little more restrictions.

Speaking of polymorphism, it's a List type. For example, you want to be able to handle both ArrayList and LinkedList with List type, and you want to be able to handle .size () and .add () with any type.

If you can handle inheritance relationships for such purposes, write them neatly in interface to make them easier to read! So the interface was provided to Java.

How the default interface was provided The root of the "abstract interface difference"

Over time, it became Java8, and the interface itself became able to have functions. It's the default function. I'm sure this story is a problem that I don't really understand the difference between abstract and interface.

The reason why this default function was provided is different from the request for abstraction so far. I think it was a measure against Moore's Law. There was a request for thorough parallelization because we wanted to save the resources of existing semiconductors as much as possible in order to be able to deal with the resource shortage problem as much as possible.

Therefore, a stream API was created to make parallel processing easy and safe, and a simple lambda expression was introduced because it was difficult to understand because it was full of anonymous classes.

In other words, default was created to provide a stream API for Moore's Law collapse countermeasures, so there is currently no rule that default can be used freely.

Summary

How to use default is basically a function required for stream API and lambda expressions, and I was not sure if I could use the default function freely. It will be nice to wait for a while.

Digression 1

You couldn't inherit multiple abstracts like interface. It seems that there is also a history of creating another abstraction function interface because it wants to inherit multiple times. (If multiple inheritance is possible, it will be difficult to track bugs, and it seems that in the past it was said to be a forbidden person or Pandora's box and was opposed.)

Digression 2 Object-oriented history

Computer is a hobby ↓ Computers are a source of business! ↓ Computers are a great industry! I want to handle programming on a larger scale! At least I want an abstraction function in programming! So I also want to save memory! ↓ High-performance Java is emerging. An abstract is also provided. ↓ It's hard to read abstract. I also want polymorphism. ↓ Providing interface ↓ Moore's Law is in jeopardy ....? I can't laugh .... Saya! Since we want to handle existing semiconductor resources effectively, let's provide a function that allows us to write thorough parallel processing in a concise manner! ↓ Providing stream API or lambda expression

I think that's how it was.

QA corner

Q. What is the purpose of the reification coercion function (override)?

A. If you want to abstract things, you need to embody the opposite. For example, when trying to implement "playing baseball," "playing soccer," and "playing tennis"

(Fictional language)

abstract sports
do (play with ??)

I think that it will be designed. Isn't it easier to force this reification every time?

@Override
do (play with "baseball")
@Override
do (play with "soccer")
@Override
do (play with "tennis")

I think it will be. So, the answer to your question is, "I wanted to design in an abstract way, so it was easy to have a concrete function."

Recommended Posts

Summary of "abstract interface differences"
interface and abstract
Proper use of interface and abstract class
Summary of OpenJDK sources
Summary of strong parameters
Summary of jar files
Summary of information security
Summary of using FragmentArgs
Summary of using DBFlow
Summary of Java support 2018
Interface / abstract class / override
Use of Abstract Class and Interface properly in Java
Advanced inheritance abstract, interface -java
Summary of FileInputStream and BufferedInputStream
[Java11] Stream Summary -Advantages of Stream-
Summary of using Butter Knife
[Java] Summary of operators (operator)
Summary of Java language basics
[Java] Summary of for statements
Summary of Java Math class
Summary of basic functions of ImageJ
Summary of 2020 programming learning output
[Java] Summary of control syntax
Summary of java error processing
[Java] Summary of design patterns
[Java] Summary of mathematical operations
[Rails Struggle/Rails Tutorial] Summary of Rails Tutorial Chapter 2
Difference between interface and abstract class
Spring Framework 5.0 Summary of major changes
[For beginners] Summary of java constructor
Summary of [Java silver study] package
[Rails] Summary of complicated routing configurations
Summary of devise controller initial state
Summary of frequently used Docker commands
[Rails] Differences and usage of each_with_index and each.with_index
Summary of object-oriented programming using Java
Summary about the introduction of Device