I
I
Igor-Novikov2019-11-02 18:43:48
Java
Igor-Novikov, 2019-11-02 18:43:48

Why create a child object by parent reference?

Very often I notice that they create child objects by parent reference.
For example: Why don't they write like this? What are the advantages of the first approach, that everyone writes this way? I understand that this is a polymorphic reference and that if we create an object in this way, we will have access to the methods of the parent and the overridden methods of the heir, but not all other methods of the heir . Why narrow down the functionality of an object in advance?
Set <String> hashSet = new HashSet<>();
HashSet <String> hashSet = new HashSet<>();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-11-02
@Igor-Novikov

SOLID

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question