We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Implement empty constructor method and constructor method with the text for Message class
Implement get_text() method for Message which will return the string variable of the Message object
Implement create_message() method for MessageFactory class by creating new Message object with given text and returning it
In order for fix_order() method to be able to sort Message objects, each Message object needs to have an id variable which is distinct for each object. Think of it like a serial number for each of the Message objects which we will use to sort them. So create an appropriate id variable in the Message class.
Then overload the < operator in Message class which should compare the id of two Message objects and return true or false accordingly if the first id is smaller or greater than the second id.
Messages Order
You are viewing a single comment's thread. Return to all comments →
Here are the things you need to do to solve this.
Message
classget_text()
method forMessage
which will return the string variable of theMessage
objectcreate_message()
method forMessageFactory
class by creating newMessage
object with given text and returning itfix_order()
method to be able to sortMessage
objects, eachMessage
object needs to have anid
variable which is distinct for each object. Think of it like a serial number for each of theMessage
objects which we will use to sort them. So create an appropriateid
variable in theMessage
class.<
operator inMessage
class which should compare theid
of twoMessage
objects and returntrue
orfalse
accordingly if the first id is smaller or greater than the second id.Below is my complete solution.