Rohit Bajaj
asked on
Modeling a class in java
HI,
I have a web application in which user can enter a rich text note.
Along with that there is also an option to write a message .
This application is used inside another chat application.
And so the rich text note that is created by user is shared with the another user along with Message.
Now the message does not seems to be logically part of a note...
I have created a note class to model it :
Note {
String body;
String title;
}
Now should i put String message also inside the note object ??
As the whole thing will be shared as a json....
If i put the message inside note its very easy to deserialize it.
On the other hand i feel that message actually is not part of the note... in that case what should i do how do i model this into a class ?
Thanks
I have a web application in which user can enter a rich text note.
Along with that there is also an option to write a message .
This application is used inside another chat application.
And so the rich text note that is created by user is shared with the another user along with Message.
Now the message does not seems to be logically part of a note...
I have created a note class to model it :
Note {
String body;
String title;
}
Now should i put String message also inside the note object ??
As the whole thing will be shared as a json....
If i put the message inside note its very easy to deserialize it.
On the other hand i feel that message actually is not part of the note... in that case what should i do how do i model this into a class ?
Thanks
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
A note is bascially a rich text whereas a message is normal text...
But probably i think they can be in one class altogether
But consider a case where what i am sending as a json object has two parts which are semantically different...
eg :
json object containing a text, name
where name and text are completely unrelated
now one way is to make a class :
class A
{
String text;
String name;
}
and send the json : {"text": "asd", "name" : "alskdj"}
Now there are some issues with this class
1) How do i name this class and should both text and name be inside the same class as there are totally different ?
Any suggestion what are possible ways to model the class or json in such a case...
But probably i think they can be in one class altogether
But consider a case where what i am sending as a json object has two parts which are semantically different...
eg :
json object containing a text, name
where name and text are completely unrelated
now one way is to make a class :
class A
{
String text;
String name;
}
and send the json : {"text": "asd", "name" : "alskdj"}
Now there are some issues with this class
1) How do i name this class and should both text and name be inside the same class as there are totally different ?
Any suggestion what are possible ways to model the class or json in such a case...
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
But in the case if user wants to send a rich text note.... He opens a web application called notes...
And enter title and body of note... and also a message in a separate box... This note appears in the chat window as a preview and message appears as it would have appeared if it was directly sent to the user...