Java Java Data Structures Efficiency! Building the Model

Dinu Comendant
Dinu Comendant
2,697 Points

When do I need to use a parameter?

This question had to come quite sooner, but I thought that with more practice I'll eventually figure it out. Still, I'm looking at the codes in the videos and still don't understand when is actually necessary to use parameters. For me, it feels like a parameter would fit everywhere and vice-versa (wouldn't fit). What questions should I give myself in order to understand if a method requires parameters in it or not?

1 Answer

Ronald Williams
Ronald Williams
Java Web Development Techdegree Graduate 25,018 Points

Here is a question you can ask yourself: Does this method require outside variables / information? Here are two scenarios to help:

1). A method that when called plays your music:

// notice there is no parameter in this method
public void play() {
    playingMusic = true;

2). A method that adds a song to your favorite playlist:

// notice this method takes a song i.e. the one you are adding to the playlist
public void addSong(Song song) {