1
\$\begingroup\$

I am making an application which fetches tweets for a specified amount of time, then inserts those tweets in a database and when the user presses another button the top n words and the hashtags will be shown.

This is my Twitter package:

[Package]Twitter
     >[Class]TwitterTools.java

This is my Analyzing package:

[Package]Analyzing
         >[Class]WordCounting.java

This is the TwitterTools class:

public class TwitterTools {

    public static List<Status> search(Query query) {
    }

    public static void filterTweetsBasedOnCity(List<Status> tweets, final String city) {
    }

    public static Query queryMaker(final String keywords, final Date since,
            final Date until, final int count) {
    }
}
  • search - returns a list of status based on a query
  • filterTweetsBasedOnCity - deletes status from a list if they were not made in a certain city
  • queryMaker - makes a query based on the parameters

This is the WordCounting class:

public class WordCounting {

    public static String getHtmlTable(final List<String[]> words, final List<String[]> hashtags) {
    }

    public static Stream<Map.Entry<String, Long>> getTopWords(final int topX, final Stream<String> words) {
    }

    public static String listToHtmlTable(List<Map.Entry<String, Long>> topEntries, final String title) {
    }
}
  • getHtmlTable - returns the html table of the top X words
  • getTopWords - returns a stream of the top words
  • listToHtmlTable - converts a list to an html table

My question is how should I arrange these two packages. Should I merge them since they have only one class each? Should I split them even more by having some of the functions in another class?

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

The ideal package structure is one which indicates usage. Classes such as these which exclusively contain static methods are definitely utility classes, which I usually put in a util subpackage of your main application.

From what it sounds like, you don't have a main package at the moment which ideally would be your website (in reverse domain order), e.g. com.stackexchange.codereview so that the more specific elements are later, then on top of that you'd have the name of your application which may make it something like com.stackexchange.codereview.tweettrends.

This would be the core of your program, and from here you could then add on your extras.

The Twitter package in particular doesn't sound helpful: your entire program seems to relate to Twitter so it doesn't really convey what that part of the program does. Frankly, I'd just put all those classes under com.stackexchange.codereview.tweettrends.util and add in more sub-packages if you add more classes.

And generally speaking, in Java packages should be exclusively lowercase.

\$\endgroup\$
3
  • \$\begingroup\$ I agree with having a main package, but I would not use com.stackexchange... as that would sound like the SE team is behind it. For this user, I would suggest com.silicontouch or similar, if no other registered domain exists. \$\endgroup\$ Commented May 12, 2014 at 21:18
  • \$\begingroup\$ I already have a "util" package named utilities so I guess I could put these two classes in there and yes I don't have a main package so I should sort that out as well. \$\endgroup\$
    – Aki K
    Commented May 12, 2014 at 21:54
  • 1
    \$\begingroup\$ @SimonAndréForsberg Yeah that was just intended as an example as he didn't mention a domain. \$\endgroup\$
    – MrLore
    Commented May 12, 2014 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.