?
Solved

Modeling a class in java

Posted on 2016-10-02
5
Medium Priority
?
91 Views
Last Modified: 2016-10-06
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
0
Comment
Question by:Rohit Bajaj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 16

Assisted Solution

by:gurpsbassi
gurpsbassi earned 400 total points
ID: 41825274
from what you have described, message seems to be part of note. Can a message exist on its own without a note?
0
 

Author Comment

by:Rohit Bajaj
ID: 41825280
Yes a message is just like any message you send in a chat application....Here also a message can be sent directly to someone ...
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...
0
 
LVL 35

Assisted Solution

by:ste5an
ste5an earned 1600 total points
ID: 41825307
Where is the semantic difference between a note and a message??
0
 

Author Comment

by:Rohit Bajaj
ID: 41831201
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...
0
 
LVL 35

Accepted Solution

by:
ste5an earned 1600 total points
ID: 41831334
note is bascially a rich text whereas a message is normal text...
So there is no semantic difference. Just formatting.

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
The S in SOLID: Separation of Concerns. Then these two parts do not belong to one object.

As the are seems to be the same (clob), just use a discriminator:

public enum BodyType { PLAINTEXT, RICHTEXT }

Note {
 String body;
 String title;
 BodyType type;
 }

Open in new window

0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question