A Simple Rule For Using Arrays

Based upon the Law of Demeter, I often am confronted with problems with a fear of creating arrays in methods and parsing them around, especially when the array falls into a collection and represents a data type almost.

For example:
// logmatches[0] ~ id of log
// logmatches[1] ~ regex of log
// logmatches[2] ~ matches
int[] logmatches = new int[3];

Now I know this is simple, but yes I often get caught creating these arrays and parsing them around, when I should rather create and object or container and use that within the collection.

// Refactor to encapusalte, but you get the idea.
public class task {
    private int id = 0;
    private String regex = “”;
    private int matchesFound = 0;
}

TTFN

Don't be shellfish...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on TumblrEmail this to someone

One thought on “A Simple Rule For Using Arrays”

Leave a Reply