aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Threaded Newsgroup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Threaded Newsgroup" Watch "Threaded Newsgroup" New topic
Author

Threaded Newsgroup

Sylvia H Charbonneau
Ranch Hand

Joined: Jul 11, 2002
Posts: 37
Hello !

I'm tasked to build a newsgroup. I will need to display messages saved in a database that are linked. For example,

Message A
\- Question A1
\- Answer A1-1
\- Answer A1-2
\- Question A2
\- Answer A2-1

Message B
Message C
\- Question C1

etc.....

All questions and answers must be displayed together when we do a message list. There must be a design pattern for something like this....I've seen newsgroups doing what I want to do, but I haven't manage to locate a design pattern.

If anyone has an answer, or a suggestion or a direction to search - I'd really appreciate it.

Thank you all kindly !

Sylvia
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
What is the difference between a message, a question and an answer - technically, I mean?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Do you actually mean a "newsgroup", i.e a cluster of messages synchronized and passed from one machine to another, typically using the NNTP protocol? Or do you mean what is more commonly known as a "forum", "bulletin board" or "BB". i.e the Big Moose Saloon here at JavaRanch?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Sylvia H Charbonneau
Ranch Hand

Joined: Jul 11, 2002
Posts: 37
Well, technically, they save different data in the database. Questions, and answers have less data.

However, there is sufficient in common that I'm leaning towards keeping the messages, questions and answers in the same table. Perhaps simplifying my queries.

Sylvia
Sylvia H Charbonneau
Ranch Hand

Joined: Jul 11, 2002
Posts: 37
Originally posted by Frank Carver:
Do you actually mean a "newsgroup", i.e a cluster of messages synchronized and passed from one machine to another, typically using the NNTP protocol? Or do you mean what is more commonly known as a "forum", "bulletin board" or "BB". i.e the Big Moose Saloon here at JavaRanch?


Nope, not the "newsgroup" type of thing. By newsgroup I meant only how message threads are displayed, the linking between them and the order that in which they are presented.

Sylvia
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Quacks like a tree to me. In a database each posting might have a reference to a single parent posting. In Java objects, a parent might have a collection of children. Does that seem to fit?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Sylvia H Charbonneau
Ranch Hand

Joined: Jul 11, 2002
Posts: 37
Originally posted by Stan James:
Quacks like a tree to me. In a database each posting might have a reference to a single parent posting. In Java objects, a parent might have a collection of children. Does that seem to fit?


Something like. It is the details that are throwing me off though. I'm ok to link Question A1 and Question A2 to Message A, but how do I link Answer A1-1 to both Message A and and Question A1, and have them displayed together

Message A
...\- Question A1
........\- Answer A1-1
........\- Answer A1-2
...\- Question A2
........\- Answer A2-1

Maybe your response answers it, but I'm pretty new so I'm not seeing it ?

Sylvia
Sylvia H Charbonneau
Ranch Hand

Joined: Jul 11, 2002
Posts: 37
Something like what is at the bottom of this page

Slashdot | Java Regular Expressions
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Sylvia H Charbonneau:

I'm ok to link Question A1 and Question A2 to Message A, but how do I link Answer A1-1 to both Message A and and Question A1, and have them displayed together


Well, if Answer A1-1 is linked to Question A1, and Question A1 is linked to Message A, Answer A1-1 already is linked to Message A implicitly, isn't it?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Sounds like trees and recursion might be new to you? Just in case, here are some basics. Trees are often made up of objects called Nodes. You can call them anything, but other folks will recognize what Node means. A node structure might have the posting and a collection of child nodes. The Posting object might have have posting title, date, author, full text, etc.

The anchor or root for the tree would have child nodes for the postings "Message-A" and "Message-B" and so on. The node for "Message-A" would have children "Question-A1" and "Question-A2". The node for "Question A1" would have children "Answer A1-1" and so on. Does that much make sense?

A recursive method - one that calls itself - will display them nicely. It will look something like:


Ilja's a master at this so I'll put him on the spot: Suggest a first test or the first thing to build. If we get helping you with code you'll find we hint at the next three or four lines rather than giving full answers. Trust me, it's more fun that way.

Did that answer the right questions?
Sylvia H Charbonneau
Ranch Hand

Joined: Jul 11, 2002
Posts: 37
Thank you ! Thank you ! Thank you !
I've been away for the last week or so, but I'll get right on this.

Sylvia
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Hi, keep us posted on how it goes!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Threaded Newsgroup