Fetching app lists, adding/removing apps from a list











up vote
0
down vote

favorite












I wrote a code that should help me fetch app lists from my database (set by different tables by their category - Microsoft Office apps, Other apps, System apps, ect').
I will add my class structure, and would like a review mainly for the architecture.
I'm not sure if I'm using the interface properly, if I even should use it like this. and if my way of extending the main class was done properly.



Firstly, I defined an interface:



Interface AppList {


// For getting lists from the database
public function getList();

// For Adding a new app to the list
public function addToList();

// For removing an app from the list
public function removeFromList();
}


Then I implement in a main class named "AppList" which is my main list class:



class Static_list implements AppList {


protected $db;
protected $table;


public function __construct() {
// get db instance
$this->db = Database::getInstance();
}


/**
*
* Gets the list by (table) name
* @param $table String Gets a name of a table (list)
* @throws Array/Boolian Returns an array of apps(/rows)
*
*/
public function getList() {

// SELECT * FROM $this->table
}


/**
*
* Adds a new app to the app lits - by (table) name
* @param $table String Gets a name of a table (list)
* @param $contents Array Gets an array of contents to apply in input.
* @throws Boolian Returns "ture" if successful, "false" if not (for mainly )
*
*/
public function addToList() {

// INSERT INTO $this->table ( field1, field2,...fieldN ) VALUES ( $contents[1], $contents[2],...$contents[N] );
}


/**
*
* Removes a new app to the app lits - by (table) name
* @param $table String Gets a name of a table (list)
* @param $id Init App ID to remove
* @throws Boolian Returns "ture" if successful, "false" if not (for mainly )
*
*/
public function removeFromList($id) {

// DELETE FROM $this->table WHERE id = $id;
}

}


As mentioned before, each list has a different table ('ms_app_list' db table, 'other_app_list' db table, 'system_app_list' db table, ect')
So for each table I'm going to have a different class that extends the main "AppList" class.



class Ms_app_list extends Static_list {

private $table = 'ms_app_list';
}

class Other_app_list extends Static_list {

private $table = 'other_app_list';
}

class System_app_list extends Static_list {

private $table = 'system_app_list';
}


So then if I want to print_r() my "system apps list", I just:



$sys_apps = new System_app_list(); 
print_r($sys_apps->getList());


Is the interface not relevant for my case? At the beginning I was thinking this was irrelevant since I use them in the main class(Static_list) and ill work without the interface too, but isn't this considered a "good practice" for code where more than one developer works on?



Should every list be a separate class that implements the interface, and extending a main class is a bad practice?



Example for only one list:



class Ms_app_list implements AppList {

private $table = 'ms_app_list';
private $db;

public function __construct() {
// get db instance
$this->db = Database::getInstance();
}

public function getList() {

// SELECT * FROM $this->table
}

public function addToList() {

// INSERT INTO $this->table ( field1, field2,...fieldN ) VALUES ( $contents[1], $contents[2],...$contents[N] );
}

public function removeFromList($id) {

// DELETE FROM $this->table WHERE id = $id;
}

}


I decided to use one main class (Static_list) with the 3 "must included methods" and extend the class to other 3 lists classes to prevent code repetition.










share|improve this question


























    up vote
    0
    down vote

    favorite












    I wrote a code that should help me fetch app lists from my database (set by different tables by their category - Microsoft Office apps, Other apps, System apps, ect').
    I will add my class structure, and would like a review mainly for the architecture.
    I'm not sure if I'm using the interface properly, if I even should use it like this. and if my way of extending the main class was done properly.



    Firstly, I defined an interface:



    Interface AppList {


    // For getting lists from the database
    public function getList();

    // For Adding a new app to the list
    public function addToList();

    // For removing an app from the list
    public function removeFromList();
    }


    Then I implement in a main class named "AppList" which is my main list class:



    class Static_list implements AppList {


    protected $db;
    protected $table;


    public function __construct() {
    // get db instance
    $this->db = Database::getInstance();
    }


    /**
    *
    * Gets the list by (table) name
    * @param $table String Gets a name of a table (list)
    * @throws Array/Boolian Returns an array of apps(/rows)
    *
    */
    public function getList() {

    // SELECT * FROM $this->table
    }


    /**
    *
    * Adds a new app to the app lits - by (table) name
    * @param $table String Gets a name of a table (list)
    * @param $contents Array Gets an array of contents to apply in input.
    * @throws Boolian Returns "ture" if successful, "false" if not (for mainly )
    *
    */
    public function addToList() {

    // INSERT INTO $this->table ( field1, field2,...fieldN ) VALUES ( $contents[1], $contents[2],...$contents[N] );
    }


    /**
    *
    * Removes a new app to the app lits - by (table) name
    * @param $table String Gets a name of a table (list)
    * @param $id Init App ID to remove
    * @throws Boolian Returns "ture" if successful, "false" if not (for mainly )
    *
    */
    public function removeFromList($id) {

    // DELETE FROM $this->table WHERE id = $id;
    }

    }


    As mentioned before, each list has a different table ('ms_app_list' db table, 'other_app_list' db table, 'system_app_list' db table, ect')
    So for each table I'm going to have a different class that extends the main "AppList" class.



    class Ms_app_list extends Static_list {

    private $table = 'ms_app_list';
    }

    class Other_app_list extends Static_list {

    private $table = 'other_app_list';
    }

    class System_app_list extends Static_list {

    private $table = 'system_app_list';
    }


    So then if I want to print_r() my "system apps list", I just:



    $sys_apps = new System_app_list(); 
    print_r($sys_apps->getList());


    Is the interface not relevant for my case? At the beginning I was thinking this was irrelevant since I use them in the main class(Static_list) and ill work without the interface too, but isn't this considered a "good practice" for code where more than one developer works on?



    Should every list be a separate class that implements the interface, and extending a main class is a bad practice?



    Example for only one list:



    class Ms_app_list implements AppList {

    private $table = 'ms_app_list';
    private $db;

    public function __construct() {
    // get db instance
    $this->db = Database::getInstance();
    }

    public function getList() {

    // SELECT * FROM $this->table
    }

    public function addToList() {

    // INSERT INTO $this->table ( field1, field2,...fieldN ) VALUES ( $contents[1], $contents[2],...$contents[N] );
    }

    public function removeFromList($id) {

    // DELETE FROM $this->table WHERE id = $id;
    }

    }


    I decided to use one main class (Static_list) with the 3 "must included methods" and extend the class to other 3 lists classes to prevent code repetition.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I wrote a code that should help me fetch app lists from my database (set by different tables by their category - Microsoft Office apps, Other apps, System apps, ect').
      I will add my class structure, and would like a review mainly for the architecture.
      I'm not sure if I'm using the interface properly, if I even should use it like this. and if my way of extending the main class was done properly.



      Firstly, I defined an interface:



      Interface AppList {


      // For getting lists from the database
      public function getList();

      // For Adding a new app to the list
      public function addToList();

      // For removing an app from the list
      public function removeFromList();
      }


      Then I implement in a main class named "AppList" which is my main list class:



      class Static_list implements AppList {


      protected $db;
      protected $table;


      public function __construct() {
      // get db instance
      $this->db = Database::getInstance();
      }


      /**
      *
      * Gets the list by (table) name
      * @param $table String Gets a name of a table (list)
      * @throws Array/Boolian Returns an array of apps(/rows)
      *
      */
      public function getList() {

      // SELECT * FROM $this->table
      }


      /**
      *
      * Adds a new app to the app lits - by (table) name
      * @param $table String Gets a name of a table (list)
      * @param $contents Array Gets an array of contents to apply in input.
      * @throws Boolian Returns "ture" if successful, "false" if not (for mainly )
      *
      */
      public function addToList() {

      // INSERT INTO $this->table ( field1, field2,...fieldN ) VALUES ( $contents[1], $contents[2],...$contents[N] );
      }


      /**
      *
      * Removes a new app to the app lits - by (table) name
      * @param $table String Gets a name of a table (list)
      * @param $id Init App ID to remove
      * @throws Boolian Returns "ture" if successful, "false" if not (for mainly )
      *
      */
      public function removeFromList($id) {

      // DELETE FROM $this->table WHERE id = $id;
      }

      }


      As mentioned before, each list has a different table ('ms_app_list' db table, 'other_app_list' db table, 'system_app_list' db table, ect')
      So for each table I'm going to have a different class that extends the main "AppList" class.



      class Ms_app_list extends Static_list {

      private $table = 'ms_app_list';
      }

      class Other_app_list extends Static_list {

      private $table = 'other_app_list';
      }

      class System_app_list extends Static_list {

      private $table = 'system_app_list';
      }


      So then if I want to print_r() my "system apps list", I just:



      $sys_apps = new System_app_list(); 
      print_r($sys_apps->getList());


      Is the interface not relevant for my case? At the beginning I was thinking this was irrelevant since I use them in the main class(Static_list) and ill work without the interface too, but isn't this considered a "good practice" for code where more than one developer works on?



      Should every list be a separate class that implements the interface, and extending a main class is a bad practice?



      Example for only one list:



      class Ms_app_list implements AppList {

      private $table = 'ms_app_list';
      private $db;

      public function __construct() {
      // get db instance
      $this->db = Database::getInstance();
      }

      public function getList() {

      // SELECT * FROM $this->table
      }

      public function addToList() {

      // INSERT INTO $this->table ( field1, field2,...fieldN ) VALUES ( $contents[1], $contents[2],...$contents[N] );
      }

      public function removeFromList($id) {

      // DELETE FROM $this->table WHERE id = $id;
      }

      }


      I decided to use one main class (Static_list) with the 3 "must included methods" and extend the class to other 3 lists classes to prevent code repetition.










      share|improve this question













      I wrote a code that should help me fetch app lists from my database (set by different tables by their category - Microsoft Office apps, Other apps, System apps, ect').
      I will add my class structure, and would like a review mainly for the architecture.
      I'm not sure if I'm using the interface properly, if I even should use it like this. and if my way of extending the main class was done properly.



      Firstly, I defined an interface:



      Interface AppList {


      // For getting lists from the database
      public function getList();

      // For Adding a new app to the list
      public function addToList();

      // For removing an app from the list
      public function removeFromList();
      }


      Then I implement in a main class named "AppList" which is my main list class:



      class Static_list implements AppList {


      protected $db;
      protected $table;


      public function __construct() {
      // get db instance
      $this->db = Database::getInstance();
      }


      /**
      *
      * Gets the list by (table) name
      * @param $table String Gets a name of a table (list)
      * @throws Array/Boolian Returns an array of apps(/rows)
      *
      */
      public function getList() {

      // SELECT * FROM $this->table
      }


      /**
      *
      * Adds a new app to the app lits - by (table) name
      * @param $table String Gets a name of a table (list)
      * @param $contents Array Gets an array of contents to apply in input.
      * @throws Boolian Returns "ture" if successful, "false" if not (for mainly )
      *
      */
      public function addToList() {

      // INSERT INTO $this->table ( field1, field2,...fieldN ) VALUES ( $contents[1], $contents[2],...$contents[N] );
      }


      /**
      *
      * Removes a new app to the app lits - by (table) name
      * @param $table String Gets a name of a table (list)
      * @param $id Init App ID to remove
      * @throws Boolian Returns "ture" if successful, "false" if not (for mainly )
      *
      */
      public function removeFromList($id) {

      // DELETE FROM $this->table WHERE id = $id;
      }

      }


      As mentioned before, each list has a different table ('ms_app_list' db table, 'other_app_list' db table, 'system_app_list' db table, ect')
      So for each table I'm going to have a different class that extends the main "AppList" class.



      class Ms_app_list extends Static_list {

      private $table = 'ms_app_list';
      }

      class Other_app_list extends Static_list {

      private $table = 'other_app_list';
      }

      class System_app_list extends Static_list {

      private $table = 'system_app_list';
      }


      So then if I want to print_r() my "system apps list", I just:



      $sys_apps = new System_app_list(); 
      print_r($sys_apps->getList());


      Is the interface not relevant for my case? At the beginning I was thinking this was irrelevant since I use them in the main class(Static_list) and ill work without the interface too, but isn't this considered a "good practice" for code where more than one developer works on?



      Should every list be a separate class that implements the interface, and extending a main class is a bad practice?



      Example for only one list:



      class Ms_app_list implements AppList {

      private $table = 'ms_app_list';
      private $db;

      public function __construct() {
      // get db instance
      $this->db = Database::getInstance();
      }

      public function getList() {

      // SELECT * FROM $this->table
      }

      public function addToList() {

      // INSERT INTO $this->table ( field1, field2,...fieldN ) VALUES ( $contents[1], $contents[2],...$contents[N] );
      }

      public function removeFromList($id) {

      // DELETE FROM $this->table WHERE id = $id;
      }

      }


      I decided to use one main class (Static_list) with the 3 "must included methods" and extend the class to other 3 lists classes to prevent code repetition.







      php object-oriented






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 18 at 14:25









      Kar19

      1175




      1175



























          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207922%2ffetching-app-lists-adding-removing-apps-from-a-list%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207922%2ffetching-app-lists-adding-removing-apps-from-a-list%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Morgemoulin

          Scott Moir

          Souastre