• Post Reply Bookmark Topic Watch Topic
  • New Topic

Handling object ID  RSS feed

 
Marc-Antoine Ouimet
Greenhorn
Posts: 3
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
What do you think would be the best way of handling object identification across different object types?
Meaning, given unique Articles, Tags and Category with an associated ID for website localization, what would be a good way of doing this?

I first thought about having each class inherit from an abstract super class that would increment the ID upon construction of another object, but given how each class of object is different from each other, perhaps it would be better for each class to have its own ID counter. In that sense, should I consider using an Identifiable interface with a getter function for an ID? I've never used interfaces before.

Regards,
Marc-Antoine
 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally I like binary masks so I'd make a unique mask for each type of ID and use that in part of ID.

I would use an interface to assign an ID, and then you can keep track easily because the ID's through discret and diverse according to object type, can be tracked as a common data type.
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marc-Antoine Ouimet wrote:What do you think would be the best way of handling object identification across different object types?
Meaning, given unique Articles, Tags and Category with an associated ID for website localization, what would be a good way of doing this?


I think we need a bit more background on these object ID's. First of all: do you want one set of ID's to cover all objects? Or is it all right if you have Article 42 and Category 42 as well? And second, do you want to persist these ID's to a database or do they only exist while your application is running?

I ask those two questions because if you start your design with the database, then the normal thing is for each database table to have its own auto-generated primary key. That key can act as an ID for the object which the row represents. So without looking to closely at your requirements, that's the best way. On the other hand you may have other requirements which conflict with that.
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, welcome to the Ranch!
 
Marc-Antoine Ouimet
Greenhorn
Posts: 3
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
I think we need a bit more background on these object ID's. First of all: do you want one set of ID's to cover all objects? Or is it all right if you have Article 42 and Category 42 as well? And second, do you want to persist these ID's to a database or do they only exist while your application is running?

I ask those two questions because if you start your design with the database, then the normal thing is for each database table to have its own auto-generated primary key. That key can act as an ID for the object which the row represents. So without looking to closely at your requirements, that's the best way. On the other hand you may have other requirements which conflict with that.


Essentially, I'm trying to make a specific static website generator. Using Java, I could have explicit links between components across different articles, and I could have each element in the site be localizable.
The way I saw this was to have each article be unique, and containing all of its translations in the same place. That way, a link from a french component of an article to a component in an english article could be refreshed once there is a french translation of that article.
Since articles make explicit references to the different types of object (Articles, Categories, Tags, Media...), I thought I could consider each type differently for the IDs. In that sense, there could be an Article 42 as well as a Category 42.

I'm beginning to learn Java and programming in general, so at first I thought I could bind everything in a Site object, and persist its data using JAXB. The problem with this would be that the entirety of the site would be saved in RAM when I then try to work on it. THis led me to consider serializing articles, categories, tags, etc. in individual files for editing. To be user-friendly, the software would have to list all of those files, which is why I thought of serializing an index file of all the articles with their ID and name (to have an overview of them). This is all inspired by the fact that Excel workbooks (.xlsx) are actually compressed archives (.zip).

I had never thought of using databases. Is it possible to run an offline database? Would the database hold all Java dynamic structures, or would it serve to index other files?
I still have the mess of localization to deal with, but it should not have an effect on the IDs.
The IDs I described in my first question are unique at the creation of the object and are intended to be used to link the contents of articles, and to separate the serialization in multiple files.
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a full DB is not needed, you could use a test file, although you'd have to deal with concurrency issues.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!