In this exercise, you will work with your partner to come up with a design for the Slack API project. Once you have a design, we will provide our design, giving you a chance to compare and contrast the two.
While we encourage you to use the provided design for this project, there is much to be gained from going through the design process before seeing our version.
- Practice the object-oriented design process
- Compare and contrast different designs for the same program
- Implement a program from a provided UML diagram
- Read through the project requirements with your partner, then follow our standard object-oriented design process.
- What are the nouns?
- How are they composed into objects and relations?
- What nouns are part of state of an object?
- What are the verbs, and which verb belongs with which object?
- What are the nouns?
- From above, we are leading you to certain classes and dependencies. We want
lib/slack.rb
to have only one dependency:Workspace
. We wantWorkspace
to have at least two dependencies:User
andChannel
. We wantWorkspace
to have manyUser
s (composition). Also, we wantWorkspace
to have manyChannel
s (composition). After reading through the requirements:- What verbs are associated with
User
? - What verbs are associated with
Channel
? - What's similar?
- What's different?
- What verbs are associated with
- The
User
andChannel
classes have similar enough verbs and responsibilities, that we could design them to have inheritance relationships... somehow.- What ideas can you come up with? What ideas do not involve User or Channel inheriting from each other?
- What would the common behaviors/methods be named?
Create a rough UML diagram for your design's first draft.
Once you have a first draft of your design, click here to see the UML for one instructor implementation.
Note that only public methods and attributes are shown.
With your partner, answer the following questions about the above design:
- What classes exist?
- Why? What are they named, what do they represent, and what state and behavior do they have?
- What composition relations exist between objects in this design?
- What inheritance relations exist between objects in this design?
- What parts of this design inspires you, and you want to steal?
- What parts of this design are you unsure about, and need to consider again later?
- What parts of this design do you think you can do without?
Final Design Question: What class(es) should `slack.rb` interact with/depend on?
slack.rb
should only interact with one class, Workspace
.
We want to minimize the number of classes it depends on if possible.
The slack.rb
file should not create, call, or use the User
, Channel
, or Recipient
classes at all. The slack.rb
file should mainly be interacting with the instance of Workspace
created in the line workspace = Workspace.new
. All User
-related information that slack.rb
receives should be returned from calling a method defined in the Workspace
class.
There's a chance that there are things about this design that aren't very clear as to why they are beneficial.
- If you're unsure about if you need users and channels to inherit from
Recipient
, try implementing the project without inheriting fromRecipient
first!- Then, afterwards, check to see if you can refactor
User
andChannel
to inherit from a newRecipient
class. It will be more visible as to why inheritance can be useful after users and channels have been built out, and you can see what the two classes have in common.
- Then, afterwards, check to see if you can refactor
- If you're unsure about what some methods mean in our UML diagram (what does
get
do? Why isself.list_all
a class method?), then try implementing the project without those method names first. Then, refactor your method names to see if they can match up with ours. Method names are hard; sometimes it's not very obvious what they're doing until you have to make a GET request. 😉 - As always, ask questions, including on Slack!
We encourage you to use our design for this project, at least as a starting point. However, if there are changes you need to make, particularly things like helper methods or extra attributes, you are welcome to do so. It's your project, after all.