Building a Simple Messaging System
Let's think about a simple text messaging system that lets its users send
messages to each other. How is this system built? What are the possible ways we
can approach this problem?
- Model the system, the system contains various users, which has messages,
they all interact somehow, etc.
- Model the each user, which has messages, and users interact
The second option seems simpler. Let's start with that. Now, let's say we want
to build a MessageBuddy class. Think back to the requirements and
design steps:
- What is the main responsibility of this class?
- What are the abilities of this class?
- What does the class have to keep track of?
Where to Start? (~20 min)
Let's start typing up our program together and then you can work in groups or
work individually to fill in more details.
Where do we start?
Some questions to consider when you are stuck:
- What objects do we need to create?
- What kind of interaction is expected? (i.e., What methods do we call?)
- What information do we need to keep track of in order for these methods
to work properly?
- What kind of output should this program display?
- Are there any "abilities" from the requirements that have not been
translated into methods in this class?
- Can this class do everything we set out in the requirements and design?
- How do we test this class?
Filling in Method Details (~20 min)
The MessageBuddy class should be able to:
- Let the user create a message
- Let the user send a message to someone
Once you have these method stubs, what do we write inside the methods to get
them to work?
Completing the Program (~20 min)
For those who are moving along quickly, here's a potential sample output of
what our program should do when we run it. Try to get your program to generate
this output as well.
Welcome to Message Buddy, Sara
Welcome to Message Buddy, Tori
Sara, type the message you want to send:
what are you doing after class?
Sara, your message has been sent
Tori, you have a new message from Sara:
what are you doing after class?
Tori, type the message you want to send:
not much, any ideas?
Tori, your message has been sent
Sara, you have a new message from Tori:
not much, any ideas?