• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Datastructure in Java

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am attaching here a file with a tree structure. It is a directory structure.

In that image D1 is a parent directory, D2,D3,D4 are subdirectories and F1, F2 represents files. I want to create my own classes which represents this directory structure.

1) Please note that I dont want to use TreeSet or any other collection because these are built in classes in Java. I want to create my classes.
2) If i create D1 as an interface or abstract class. for example D1 is abstract class the D2,D3,D4 must extends D1 but problem is in future if I want to create another subdirectory lets say D5 then I have to create a new subclass as D5. That means for each new sudbdirectory creation I have to create anew class. This is not correct. I want to create classes such as by simply creating object of those classes we can create subdirectory.

Could you please help me to resolve this problem
Pic1.jpg
[Thumbnail for Pic1.jpg]
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I want to create my own classes which represents this directory structure.


Don't think I read you well. Can you elaborate your requirement a little bit ? Are you trying to design a class heirarchy and/or a data structure for storing some objects of arbitrary classes ?

And Welcome to Javaranch
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The diagram/description you have provided conveys the following information.

1) It is a parent child relationship.
2) All objects in the chain are of the same type.
3) All object can contain a collection of similar objects (parent having children)
4) All children might need to know who the parent is. (this would depend on your requirement)

As you can see, you really need to design an object which will satisfy these criteria.
If you agree to this premise, how would you design the object?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please check out the javax.swing.tree.TreeNode interface for pointers.
 
He's giving us the slip! Quick! Grab this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic