c# - Abstract Factory Pattern for Implementing AdNetworks on Multiple Platforms -


here's link github project.

i want implement abstract factory instead of adding platform dependent compilation flags in 1 file , make ugly. hence decoupled code. moreover, have implement different adnetworks on different platforms.

this interface

public interface iads  {     void showvideoad();     void preloadvideoad();     bool isadavailable();  } 

and platformadcontroller(android, ios, amazon, windows) implement interface.

    public class amazonadscontroller : iads     { // code goes here     } 

then in somefactoryclass i'll

public iads getobject() {     #if unity_android     if(platform == amazon)     return new amazonadscontroller     else      return new androidadscontroller     #elif unity_ios     return new iosadscontroller     #elif unity_wp10     return new windowsadscontroller } 

this method called admanager singleton monobehaviour. current admanager state is

namespace ms.ads {     [requirecomponent(typeof(keygenerator))]     public class admanager : monobehaviour     {         #region fields & properties         [serializefield]         private keyssource _keyssource;         [serializefield]         [hideininspector]         private string _filename;         [serializefield]         [hideininspector]         private string _url;          // source keys         public keyssource source         {             { return _keyssource; }             set { _keyssource = value; }         }          // web url adkeys         public string url         {             { return _url; }             set { _url = value; }         }          // filename adkeys e.g adc.json         public string filename         {             { return _filename; }             set { _filename = value; }         }          // replaced factoryobject.         private fybercontroller _fybercontroller;         #endregion          #region message methods         void start()         {                         getcomponent<keygenerator>().generatekeys(source, url, filename);             _fybercontroller = new fybercontroller();             _fybercontroller.requestvideoad();         }         #endregion          #region methods         public void showad()         {             if (_fybercontroller.isvideoadavailable)                 _fybercontroller.showvideoad();         }          public bool isvideoadavailable()         {             return _fybercontroller.isvideoadavailable ? true : false;         }         #endregion     } } 

what know

  1. is factory pattern right choice here?
  2. if yes, should go interface or abstract base class or base class virtual methods?

1- yes can use factory pattern here, , totally fine that. tomorrow if have ads can add factory.

2- there 2 ways create factory patterns. abstract factory pattern delegates responsibility of object instantiation object via composition , factory method pattern uses inheritance , relies on subclass handle desired object instantiation. depends on needs.

in case, using factory method pattern. more easier use abstact factory pattern.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -