NotionCommotion Posted February 11, 2018 Share Posted February 11, 2018 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(); } Quote Link to comment Share on other sites More sharing options...
ignace Posted February 11, 2018 Share Posted February 11, 2018 You would have a PilotMapper, a DoctorMapper, and a TeacherMapper obviously. Which would extend from PersonMapper where all the Person mapping would take place. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted February 11, 2018 Author Share Posted February 11, 2018 So, for every specific entity, I would have two classes? One for the entity and one for the associated mapper? Quote Link to comment Share on other sites More sharing options...
requinix Posted February 11, 2018 Share Posted February 11, 2018 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. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted February 11, 2018 Author Share Posted February 11, 2018 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.