From day today I want to leran more about, how an application is designed/structured. So I read something about the facade pattern an got a little question about this pattern. First of all, a short introduction to my project:
My Project My project is a Multimedia Application. On the one side there is the MultimediaApllication, which got different Views (e.g Musicscreen,Videoscreen ...) ont the other side there is my IRController which allows you to control the application. The MultimediaApplication works without an IRController, because it listen to KeyEvents (e.g 'enter' pressed). The IRController is like a little own System: IRController
This enum creates a key object if a key is pressed on the ircontroller
public enum
/*
Example Values
*/
VOL_UP(new MediaVolumeUpKey()),
VOL_DOWN(new MediaVolumeDownKey()),
MUTE(new MediaMuteKey());
private byte bytes[];// Repräsentiert den Key
private Key k;
private Keys(Key key){
this.k = key;
}
public static Key getKey(byte[] bytes){
for(Keys key: values()){
if(Arrays.equals(key.getBytes(), bytes)){
return key.k;
}
}
return null;
}
public byte[] getBytes(){
return this.bytes;
}
public Key getKey(){
return this.k;
}
}
And this is the abstarct Key class. All Keys entends Key.
public abstract class Key {
private byte[] bytes;
protected Key(int...bytes){//int... als argumente für übersichtlichen Code
byte[] temp = new byte[bytes.length];
for(int i =0; i<bytes.length;i++) temp[i] = bytes[i];
this.bytes = temp;
}
public byte[] getBytes(){return bytes;}
public void abstract call();
}
public static Key getKey(byte[] bytes){
for(Keys key: values()){
if(Arrays.equals(key.getBytes(), bytes)){
return key.k;
}
}
return null;
}
public byte[] getBytes(){
return this.bytes;
}
public Key getKey(){
return this.k;
}
Now when I change my IRController I just need to change the bytecode for the key.
The problem is know the communication between the key classes and the multimedia application. That everything is loosely coupled, I thought maybe its a good idea to build a facade around the multimedia application. So the key class can call a play() stop() pause() volUp() of the facade and the facade decide how to act when the method is called.
Can I implemnt my idea like this?Or should I better ask, have I understood the facade pattern right? Thanks for your help :)