mercredi 3 juin 2015

Thirdy Party Authentication Oauth with Adapter Patter Design

I am writing a third party authentication method for facebook and google+ currently.

I decided to use adapter design pattern and this is my first time that I am following design patterns

Here is my design structure

public interface IThirdPartyAuthenticationAdapter{
   bool Login();
}

public Class ThirdPartyAuthenticationAdapter : IThirdPartyAuthenticationAdapter
{
    private readonly IThirdPartyAuthenticationAdapter _thirdPartyAuthentication;

    public ThirdPartyAuthenticationAdapter (IThirdPartyAuthenticationAdapter thirdPartyAuthentication){
         _thirdPartyAuthentication = thirdPartyAuthentication;
    }
    public bool Login()
    {
        return _thirdPartyAuthentication.Login();
    }

}

public class GooglePlusAuthentication : IThirdPartyAuthenticationAdapter{
   public bool Login(){
      return false;
   }
}

public class FacebookAuthentication : IThirdPartyAuthenticationAdapter{
   public bool Login(){
      return true;
   }
}

Register Container

container.Register<IThirdPartyAuthenticationAdapter, GooglePlusAuthentication >();
container.Register<IThirdPartyAuthenticationAdapter,FacebookAuthentication>();

Usage

   private IThirdPartyAuthenticationAdapter
   bool GoogleLoginResult = container.Resolve<GooglePlusAuthentication >().Login();

My question is really simple. Is this implementation is right?

Aucun commentaire:

Enregistrer un commentaire