Adapter pattern without the use of interfaces -


i'm trying understand if adapter pattern implementation dependent on interface realizations. read, should use adapter when need convert interface of class interface clients expect.

i have been told classic example of 3 pronged plug using adapter connect 2 pronged plug...

so, understand, if method in class has method specific paramater signature, , want wrap logic require more (or less) paramaters, should implement adapter pattern.

from examples iv'e seen, proper way create adapter class realizes interface desired method signature, , hold adoptee member in adapter class. then, can call adpotee method through realized interface method , input logic.

the question is, if need use 1 adoptee class, why use interface? not simpler drop interface bit , hold adoptee member , implement desired logic in "stand alone" method?

is required realize interface method here adapter pattern valid?

public class poststatusadapter {     public interface ipoststatus      {          void post(string i_post, string i_password);     }      public class useradapter : ipoststatus     {         user adoptee = new user();          void ipoststatus.post(string i_post, string i_password)         {             if (passwordcorrect(i_password))             {                 adoptee.poststatus(i_post);             }         }          private bool passwordcorrect(string i_password) { ... }     } } 

yes, it's adapter if implements "external" interface or abstract api -- regardless of whether "internal" connection formalized interface or abstract api.

so it's still adapter when hooks onto specific internal implementation, can fulfill/ answer contract & methods of external interface.

it may no longer adapter if implement significant logic within adapter -- becomes delegate.

delegates implement functionality both & delegating referenced object.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -