简体   繁体   中英

package private static member class vs. package private class

I was writing two implementations of a Linked List for an assignment, a Doubly Linked List and a Circular Doubly Linked List. Now as the class representing a Link within the Linked List is the same in both implementations, I want to use it in both.

Now I wonder which approach would be better:

Implement the Link class as a package-private static member class in the first implementation and then use this class in the second implementation or make the Link class a package-private class.

You could move Link up as static member class of a common base class / interface (if you have one). This solution would express that Link is strongly associated with (both implementations of) the linked list.

没有理由使Link类与第一个实现比与第二个实现更紧密相关,因此我建议使用第二种方法。

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