I am building an user class that manage the creation, deletion and modification of a generic user. My class should be used in this way:
# creation
user::create($username, $password, $email); // Does not need of $id
# modification
$u = new user($id);
$u->edit('password', $new_password);
# deletion
$u->delete();
Basically the class contain a static method create() that obliviously does not require the used id as argument. After the creation you can gather user infos and manage the user creating an instance of the class user and set as argument the $id of the user.
Is that a good design or should i create something like:
# creation
$users = new genericUserMethod();
$users->create($username, $password, $email);
# modification
$u = new specificUser($id);
$u->edit('password', $new_password);
# deletion
$u->delete();
…Creating 2 different classes. Or is there any other way?
This could be an approach:
Usage sample:
You can even define static methods in the class like
getActiveUsers()that returns an array with the active users for example…Note: This is intended for quite simple needs, in case you require to do dome complex things I would recommend you to use an ORM library as pointed @What is the question