简体   繁体   中英

Create your own data structure class or use existing implementation?

So I've been going through data structure, I can create my own linkedlist class with its functions ( insert, remove, length etc ) but why should I do that when I can simply do the following

LinkedList<>list = new LinkedList<>();

One good justification to the question is: Spring models or Spring POJOs.

It can be troublesome to have bean of type Map in old Spring for example and autowire it, but if you create a class that extends Map or that failing type then it will work:

public class MyDataContainer extends Map<int, String> {
...
}

Another use is when you want to perform custom action on get or set, then extending Data Structure type and overriding one of its getters or setter can be useful, example: strip value from extra spaces before setting or putting it in the List , Map , or whatever data structure you've modified. I've actually had to do that couple times over the course of my career.

Generally, this question asked in an interview, design the functionality for LinkedList. 
If you have deep knowledge of LinkedList, then you can design the LinkedList for different languages.
Custom LinkedList implementation will check your deep understanding, how it works internally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM