java - The code refers to the Collection by its interface type (eg., Set) rather than by its implementation type -
I mostly add AOC code to its interface type (for example, set) instead of its implementation type.
The reason for the reason below is,
This is a highly recommended programming practice because it gives you the flexibility to change the constructor to change only the implementation. Any one of the variables used to store or store is declared as the type of implementation of the archive rather than its interface type, all such variables and parameters should be changed to change its implementation type. .
In addition to the line, the author provides there is no guarantee that the resulting program will work. If the program uses the non-standard operation in the original implementation types , Not new , the program will fail In the context of the collection, it only prevents you from using any nonstandard operations with their interface.
What is the author that talks about non-standard operations?
Secondly, in the context of collection, does it prevent any non-standard operations from using their interface?
Please expand with the help of java code?
An example is linkedlist
for which getFirst () < / Code> and
found ()
method seems convenient to use them, but if the implementation changes to ArrayList
, they are gone.
Comments
Post a Comment