Hi,
ich habe insgesamt 6 solcher Klassen. Alle nur eben mit anderen Objekten, also nicht Action, sondern irgendeine andere Klasse.
Ansonsten sind sie, bis auf ein paar Kleigkeiten wie removeAction(String name) heisst dann in der anderen Klasse removeAction(String account), also immer das wo durch man die Klasse identifizieren kann.
Nun ist meine Frage, kann ich die irgendwie zusammenfassen?
Ich habe z.B. gedacht, eine Oberklasse, die dann beerbt wird.
Oder wie mach ich das am besten?
[HIGHLIGHT="Java"]import java.util.Vector;
public class Actions {
private Vector<Action> actions;
public Actions() {
super();
}
public final Vector<Action> getActions() {
if (actions == null) actions = new Vector<Action>();
return actions;
}
public Action getAction(String name) {
int idx = getActions().indexOf(new Action(name));
if (idx < 0) return null;
return getActions().get(idx);
}
public boolean removeAction(String name) {
return getActions().remove(new Action(name));
}
public boolean addAction(Action action) {
if (getActions().contains(action)) return false;
return getActions().add(action);
}
public int size() {
return getActions().size();
}
public String toString() {
return this.getActions().toString();
}
}
[/HIGHLIGHT]
ich habe insgesamt 6 solcher Klassen. Alle nur eben mit anderen Objekten, also nicht Action, sondern irgendeine andere Klasse.
Ansonsten sind sie, bis auf ein paar Kleigkeiten wie removeAction(String name) heisst dann in der anderen Klasse removeAction(String account), also immer das wo durch man die Klasse identifizieren kann.
Nun ist meine Frage, kann ich die irgendwie zusammenfassen?
Ich habe z.B. gedacht, eine Oberklasse, die dann beerbt wird.
Oder wie mach ich das am besten?
[HIGHLIGHT="Java"]import java.util.Vector;
public class Actions {
private Vector<Action> actions;
public Actions() {
super();
}
public final Vector<Action> getActions() {
if (actions == null) actions = new Vector<Action>();
return actions;
}
public Action getAction(String name) {
int idx = getActions().indexOf(new Action(name));
if (idx < 0) return null;
return getActions().get(idx);
}
public boolean removeAction(String name) {
return getActions().remove(new Action(name));
}
public boolean addAction(Action action) {
if (getActions().contains(action)) return false;
return getActions().add(action);
}
public int size() {
return getActions().size();
}
public String toString() {
return this.getActions().toString();
}
}
[/HIGHLIGHT]