Jump to content

Chicken or the egg conundrum when working with entities


NotionCommotion

Recommended Posts

 
getById($id) and add($data) seems to belong in the PersonMapper class.  But PersonMapper shouldn't need to know all the specific properties for each entity to return for getById(), what to do with the data received by add(), etc and we should go straight from the horse's mouth.  But we can't create a specific entity without knowing which type of entity to create, and even if we added a getEntityTypeById() method, it doesn't seem to make sense for a DoctorEntity object or even PersonEntity object to have a getById() method but only a getProperties() method to return their own properties.  I was thinking maybe I need some sort of "prototype" class (or probably classes), but this seems like a slippery slope.  How should this be modeled?
 
PS.  Sorry, just can't help these abstract discussions.  I am actually reevaluating how I structure applications and will be doing something with users and administrators, but haven't started yet.
class PersonMapper  /*maybe this is really a PersonCollection, PersonContainer, etc???*/
{
    public function getById($id);
    public function add($data);
    public function delete($id);
}
class PersonEntity
{
    protected $name, $age, $sex;
    public function walk();
    public function talk();
    public function eat();
    abstract public function getProperties();
}
class PilotEntity extends PersonEntity
{
    protected $airline;
    public function fly();
    public function land();
    public function getProperties();
}

class DoctorEntity extends PersonEntity
{
    protected $internHospital;
    public function cure();
    public function prescribeMedicine();
    public function getProperties();}

class TeacherEntity extends PersonEntity
{
    protected $gradesTaught=[];
    public function grade();
    public function giveDetention();
    public function getProperties();
}

 

Link to comment
Share on other sites

Right. The mapper maps between the implementation and the data, so every pair of those you have needs a mapper to go with them.

 

It's not like the mappers have to be completely separate from each other. You could have the PilotMapper extend the PersonMapper - in fact the PersonMapper should be abstract (to match PersonEntity) so you have to extend it.

Link to comment
Share on other sites

Right. The mapper maps between the implementation and the data, so every pair of those you have needs a mapper to go with them.

 

It's not like the mappers have to be completely separate from each other. You could have the PilotMapper extend the PersonMapper - in fact the PersonMapper should be abstract (to match PersonEntity) so you have to extend it.

 

Ah, I was incorrectly thinking that the mapper was some sort of list/collection/container class, and didn't like the fact that it also contained specific entity knowledge...

 

Was also wondering why such a misleading name of "mapper" was being used.  :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.