This is my command interface:
public interface IConverter {
void convert();
}
This is my Receiver class:
public class Ogg extends Audio{
private File src;
private File trgt;
public static final String CODEC = "libvorbis";
public static final String FORMAT = "ogg";
public Ogg(File src, File trgt){
this.src = src;
this.trgt = trgt;
}
public void convertToOgg(){
audioAttr.setCodec(CODEC);
encoAttrs.setFormat(FORMAT);
encoAttrs.setAudioAttributes(audioAttr);
try {
encoder.encode(src, trgt, encoAttrs);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
}
And this is my Concrete Command:
package org.hitplay.audio.converters;
public class OggConverter implements IConverter {
private Ogg ogg;
public OggConverter(Ogg ogg){
this.ogg = ogg;
}
@Override
public void convert() {
ogg.convertToOgg();
}
}
This is my Invoker class:
public class AudioConverter {
IConverter audio;
public AudioConverter(IConverter audi){
this.audio = audi;
}
public void setAudio(IConverter audio){
this.audio = audio;
}
public void convert(){
audio.convert();
}
}
I have currently studied the command design pattern on this link and I was wondering if I have implemented the design pattern correctly. f I do not, please tell me why, and how else I can improve this code. Also, I have other classes besides Ogg and OggConverter
; I also have Mp3
and Mp3Converter
.