Skip to main content
Code Review

Return to Answer

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

Yes, this is a Singleton class. Or actually, technically this is not even a singleton as it doesn't appear to be instantiated at all.

What makes it similar to a singleton class though is that there is only, and can be only one variable of these:

private static ArrayList<Song> songList;
private static ArrayList<Album> albumList;

Overall, it is a bad idea to have static variables like this.

Some few additional comments:

  • Make your variables final
  • Declare as List and instantiate as ArrayList

So this would be better:

private static final List<Album> albumList = new ArrayList<Album>();

However, ask yourself these two questions: Does the order of the albums matter? Should it be possible to have two equal objects in the list? If the answer to both these questions is No, then it would be better of as Set<Album> albums = new HashSet<Album>();

Additionally, you can see a previous answer of mine previous answer of mine related to the Singleton pattern in Android, in this case I would recommend janos' approach though.

Yes, this is a Singleton class. Or actually, technically this is not even a singleton as it doesn't appear to be instantiated at all.

What makes it similar to a singleton class though is that there is only, and can be only one variable of these:

private static ArrayList<Song> songList;
private static ArrayList<Album> albumList;

Overall, it is a bad idea to have static variables like this.

Some few additional comments:

  • Make your variables final
  • Declare as List and instantiate as ArrayList

So this would be better:

private static final List<Album> albumList = new ArrayList<Album>();

However, ask yourself these two questions: Does the order of the albums matter? Should it be possible to have two equal objects in the list? If the answer to both these questions is No, then it would be better of as Set<Album> albums = new HashSet<Album>();

Additionally, you can see a previous answer of mine related to the Singleton pattern in Android, in this case I would recommend janos' approach though.

Yes, this is a Singleton class. Or actually, technically this is not even a singleton as it doesn't appear to be instantiated at all.

What makes it similar to a singleton class though is that there is only, and can be only one variable of these:

private static ArrayList<Song> songList;
private static ArrayList<Album> albumList;

Overall, it is a bad idea to have static variables like this.

Some few additional comments:

  • Make your variables final
  • Declare as List and instantiate as ArrayList

So this would be better:

private static final List<Album> albumList = new ArrayList<Album>();

However, ask yourself these two questions: Does the order of the albums matter? Should it be possible to have two equal objects in the list? If the answer to both these questions is No, then it would be better of as Set<Album> albums = new HashSet<Album>();

Additionally, you can see a previous answer of mine related to the Singleton pattern in Android, in this case I would recommend janos' approach though.

added 440 characters in body
Source Link
Simon Forsberg
  • 59.7k
  • 9
  • 157
  • 311

Yes, this is a Singleton class. Or actually, technically this is not even a singleton as it doesn't appear to be instantiated at all.

What makes it similar to a singleton class though is that there is only, and can be only one variable of these:

private static ArrayList<Song> songList;
private static ArrayList<Album> albumList;

Overall, it is a bad idea to have static variables like this.

Some few additional comments:

  • Make your variables final
  • Declare as List and instantiate as ArrayList

So this would be better:

private static final List<Album> albumList = new ArrayList<Album>();

However, ask yourself these two questions: Does the order of the albums matter? Should it be possible to have two equal objects in the list? If the answer to both these questions is No, then it would be better of as Set<Album> albums = new HashSet<Album>();

Additionally, you can see a previous answer of mine related to the Singleton pattern in Android, in this case I would recommend janos' approach though.

Yes, this is a Singleton class. Or actually, technically this is not even a singleton as it doesn't appear to be instantiated at all.

What makes it similar to a singleton class though is that there is only, and can be only one variable of these:

private static ArrayList<Song> songList;
private static ArrayList<Album> albumList;

Some few additional comments:

  • Make your variables final
  • Declare as List and instantiate as ArrayList

Additionally, you can see a previous answer of mine related to the Singleton pattern in Android, in this case I would recommend janos' approach though.

Yes, this is a Singleton class. Or actually, technically this is not even a singleton as it doesn't appear to be instantiated at all.

What makes it similar to a singleton class though is that there is only, and can be only one variable of these:

private static ArrayList<Song> songList;
private static ArrayList<Album> albumList;

Overall, it is a bad idea to have static variables like this.

Some few additional comments:

  • Make your variables final
  • Declare as List and instantiate as ArrayList

So this would be better:

private static final List<Album> albumList = new ArrayList<Album>();

However, ask yourself these two questions: Does the order of the albums matter? Should it be possible to have two equal objects in the list? If the answer to both these questions is No, then it would be better of as Set<Album> albums = new HashSet<Album>();

Additionally, you can see a previous answer of mine related to the Singleton pattern in Android, in this case I would recommend janos' approach though.

Source Link
Simon Forsberg
  • 59.7k
  • 9
  • 157
  • 311

Yes, this is a Singleton class. Or actually, technically this is not even a singleton as it doesn't appear to be instantiated at all.

What makes it similar to a singleton class though is that there is only, and can be only one variable of these:

private static ArrayList<Song> songList;
private static ArrayList<Album> albumList;

Some few additional comments:

  • Make your variables final
  • Declare as List and instantiate as ArrayList

Additionally, you can see a previous answer of mine related to the Singleton pattern in Android, in this case I would recommend janos' approach though.

lang-java

AltStyle によって変換されたページ (->オリジナル) /