Note that there are some explanatory texts on larger screens.

plurals
  1. PODesign pattern for users
    primarykey
    data
    text
    <p>I'm starting to code my project and I have used, in some past unfinished project, two different patterns to manage the design of a user class that will need to manage the following things:</p> <ul> <li>The creation of a user</li> <li>The edits to a user</li> <li>The deletion of a user</li> <li>The reading of user data</li> </ul> <p>Despite this, we have also to consider that this user class will be extended by the session class which will just set the focused user id as the id provided by the user who is viewing the pages.</p> <p>We will also have this class <code>users</code> that will manage instead groups of users.</p> <p>The 2 options I used are the following (simplified):</p> <p><strong>Different class for different purpose</strong></p> <pre><code>- class UserMaker($username, $password, $email); function giveBirth(); // create the user - class UserManager($id); function edit($field, $value); // edit a specific user field function save(); // save all the edits with a single query function setTrusted(); // set that user as trusted function setAdmin(); // set that user as admin function setBanned(); // ban the specific user - class UserReader($id); function get($field); // Get the value of a single field function getAll(); // Get all fields from that user as associative array function isAdmin(); // self explanation function isRegistered(); // self explanation function isBanned(); // self explanation </code></pre> <p><strong>Single class</strong></p> <pre><code>- class User($id); function static giveBirth($username, $password, $email); // create the user, notice this is static function edit($field, $value); // edit a specific user field function save(); // save all the edits with a single query function setTrusted(); // set that user as trusted function setAdmin(); // set that user as admin function setBanned(); // ban the specific user function get($field); // Get the value of a single field function getAll(); // Get all fields from that user as associative array function isAdmin(); // self explanation function isRegistered(); // self explanation function isBanned(); // self explanation </code></pre> <p>Basically, since the only class that does not accept $id as argument for the <code>__construct()</code> is UserMaker we just set the function <code>giveBirth()</code> as static so we can create the user.</p> <p>What is the best way to design this pattern? Have you got a third-option which you feel better than these?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload