I have three non-static classes representing a musical composition. This is the class Score, Part and Note.
Score contains an ArrayList<Part> instance variable representing several parts of the tool, and Part contains an ArrayList<Note> instance variable representing a sequence of notes.
public class Score { private ArrayList<Part> parts; private int resolution; public Score(int resolution) { parts = new ArrayList<Part>(); this.resolution = resolution; } public void addPart(Part part) { parts.add(part); } public ArrayList<Part> getParts() { return parts; } public int getResolution() { return resolution; } } public class Part { private ArrayList<Note> notes; public Part() { notes = new ArrayList<Note>(); } public void addNote(Note note) { notes.add(note); } public ArrayList<Note> getNotes() { return notes; } } public class Note() { private long startStamp; private long endStamp; private int resolution; public Note(long startStamp, long endStamp, int resolution) { this.startStamp = startStamp; this.endStamp = endStamp; this resolution = resolution; } public double getDuration() { int duration = (double) (getEndStamp() - getStartStamp()) / resolution; return duration; } }
The duration of each note is calculated using the resolution resolution. The resolution of a particular instance of Score is passed through the Note construtor each time a note instance is created. A note is added to the ArrayList<Note> notes corresponding Part instance, and a part is added to the ArrayList<Part> parts Score instance.
My decision to use int resolution as a parameter of the Note constructor does not seem elegant, since there are many notes that belong to the same account, that is, the resolution is an evaluation attribute, not an attribute of a note.
Is there a way to get permission by referencing the corresponding Score object from the Note class, instead of passing the permission through the constructor of the Note class, or maybe some other solution?
source share