Messages Order

  • + 0 comments

    Message's id assignment should be handled by the factory.

    class Message {
    public: 
        Message() {}
        Message(string text, int id):msg_body(text), msg_id(id) {}
        const string& get_text() {
            return msg_body;
        }
        bool operator<(const Message& other) const {
            return this->msg_id < other.msg_id;
        }
        
    private:
        string msg_body;
        int msg_id;
    };
    
    class MessageFactory {
    public:
        MessageFactory() {}
        Message create_message(const string& text) {
            msg_counter += 1;
            return Message(text, msg_counter);
        }
    private:
        int msg_counter = -1;
    };