#Checking whether having nested classes is a good idea
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
It depends, I would say. If a class is only used by another class, e.g. to group recurring attributes internally, it might be a good idea to do so, in order to avoid pollution of the public namespace. But in case that the potential nested class represents a more general concept or this class is also exposed by the super class via getters/setters or other methods, I would tend to make them standalone.
For me "Coordinate" sounds like a more general concept, so I would assume it is a standalone class
It really is only used for one class, these are the classes for reference:
public record Coordinates(double longitude, double latitude) {
@JsonCreator
public Coordinates(double[] coordinates) {
this(coordinates[0], coordinates[1]);
}
} ```
Detected code, here are some useful tools:
public class NoFlyZone {
private String name;
private ArrayList<Coordinates> coordinates;
public NoFlyZone(@JsonProperty("name") String name, @JsonProperty("coordinates") ArrayList<Coordinates> coordinates){
this.name = name;
this.coordinates = coordinates;
}
public String getName() {
return name;
}
public ArrayList<Coordinates> getCoordinates() {
return coordinates;
}```
Detected code, here are some useful tools:
public class NoFlyZone {
private String name;
private ArrayList<Coordinates> coordinates;
public NoFlyZone(@JsonProperty("name") String name, @JsonProperty("coordinates") ArrayList<Coordinates> coordinates) {
this .name = name;
this .coordinates = coordinates;
}
public String getName() {
return name;
}
public ArrayList<Coordinates> getCoordinates() {
return coordinates;
}
Since you return the Coordinates via getter, there is a high chance that another class need to use coordinates as well... Also pls return a List instead of an ArrayList... In your example I would tend to a standalone class+
Yeah i only use the getter in once in one method, would this make a difference?
on whether to nest them or not
@cinder onyx please stop reposting the same question several times
Sorry, i just wasnt sure if it was deviating from my original question