forked from nus-cs2103-AY2425S1/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract out the logic of checking Gopher message type to Message.java
Currently, Gopher's response will be styled as red background if the response is a warning message that contains text "Please try again". Even though such implementation works in most cases, it will introduce styling error in the system if user creates a task with "Please try again" as part of its name, hence affecting user experience. Also, such way of recognizing message type and styling is not very extensible and flexible, hence a better idea would be extract out the logic to another class to explicitly handle this, so as to provide more flexibility when similar features need to be developed in the future. As a result, Message class is created to wrap around the text returned by Gopher so that other information such as message type can be input and pass around the program for checks. This offers more flexibility as compared to the initial approach and hence should be included in the latest update
- Loading branch information
1 parent
f6c0e45
commit bde26d3
Showing
8 changed files
with
214 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package gopher.message; | ||
|
||
/** | ||
* Represents message returned by Gopher when user input any commands. | ||
* Contains information such as text, message type. | ||
*/ | ||
public class Message { | ||
private String text; | ||
private MessageType type; | ||
|
||
/** | ||
* Constructor for Message class. | ||
* | ||
* @param text text within the message | ||
* @param type type of message, specified by MessageType Enum class | ||
*/ | ||
public Message(String text, MessageType type) { | ||
this.text = text; | ||
this.type = type; | ||
} | ||
|
||
/** | ||
* Gets the type of the Message Object | ||
* | ||
* @return type of message | ||
*/ | ||
public MessageType getType() { | ||
return this.type; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return text; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package gopher.message; | ||
|
||
/** | ||
* Types of messages that Gopher would respond to the user | ||
* @see #TEXT | ||
* @see #ERROR | ||
*/ | ||
public enum MessageType { | ||
/** | ||
* Normal text message | ||
*/ | ||
TEXT, | ||
/** | ||
* Error message | ||
*/ | ||
ERROR | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.