How do I use facade design pattern -
from day today want leran more about, how application designed/structured. read facade pattern got little question pattern. first of all, short introduction project:
my project project multimedia application. on 1 side there multimediaapllication, got different views (e.g musicscreen,videoscreen ...) ont other side there ircontroller allows command application. multimediaapplication works without ircontroller, because hear keyevents (e.g 'enter' pressed). ircontroller little own system: ircontroller
this enum creates key object if key pressed on ircontroller
public enum /* illustration 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)){ homecoming key.k; } } homecoming null; } public byte[] getbytes(){ homecoming this.bytes; } public key getkey(){ homecoming this.k; } }
and abstarct key class. 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 =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)){ homecoming key.k; } } homecoming null; } public byte[] getbytes(){ homecoming this.bytes; } public key getkey(){ homecoming this.k; }
now when alter ircontroller need alter bytecode key.
the problem know communication between key classes , multimedia application. loosely coupled, thought maybe thought build facade around multimedia application. key class can phone call play() stop() pause() volup() of facade , facade decide how deed when method called.
can implemnt thought this?or should improve ask, have understood facade pattern right? help :)
about
have understood facade pattern right?
i think - yes. facade design pattern more known provide unified interface set of interfaces in subsystem. in case think can used define higher-level implementation makes subsystem easier use.
hiding implementation details concept of encapsulation. other users beingness provided things need know/use , actual processing left 1 responsible it.
since you're considering
change ircontroller
one possible solution proxy design pattern. allows provide surrogate or placeholder object (lets assume class key
) command access it.
update:
you can consider code apache commons stringutils:
public static string[] splitbycharactertype(final string str) { homecoming splitbycharactertype(str, false); } private static string[] splitbycharactertype(final string str, final boolean camelcase) { // code... }
as can see parameters 2 in splitbycharactertype(final string str, final boolean camelcase)
, 1 exposed outer world via splitbycharactertype(final string str)
. can apply case of key
class design.
design-patterns design javafx facade
No comments:
Post a Comment