A DataMapper under the domain mapper model?
I have only recently found out about 'Data Mappers' which allows data to be passed into classes without said classes knowing where the data comes from.
So, so here is my attempt to write one:
I am asking whether this code could be improved in general, and I am interested in particular whether it could be optimized the. That way, I won't have to create a distinct mapper class for the every entity, as they all seem identical to me, making a lot of duplicated code.
A DataMapper under the domain mapper model?
I have only recently found out about 'Data Mappers' which allows data to be passed into classes without said classes knowing where the data comes from.
So here is my attempt to write one:
I am asking whether this code could be improved in general, and I am interested in particular whether it could be optimized the way I won't have to create a distinct mapper class for the every entity, as they all seem identical to me, making a lot of duplicated code.
A DataMapper under the domain mapper model
I have only recently found out about 'Data Mappers' which allows data to be passed into classes without said classes knowing where the data comes from, so here is my attempt to write one:
I am asking whether this code could be improved in general, and I am interested in particular whether it could be optimized. That way, I won't have to create a distinct mapper class for the every entity, as they all seem identical to me, making a lot of duplicated code.
- 9.1k
- 1
- 22
- 51
Is this the right way to make a A DataMapper under the domain mapper model?
Hopefully i am asking this on the right stack exchange forum. If not please do let me know and I will ask somewhere else.
As I have self learned PHP and all programming in general, I have only recently found out about 'Data Mappers' which allows data to be passed into classes without said classes knowing where the data comes from. I have read some of the positives of using mappers and why they make it 'easier' to perform upgrades later down the line, however I am really struggling to find out the recommended way of using mappers and their layouts in a directory structure.
The way I have been using/creating mappers (as well as the file structure is as follows). The code below represents the real life use case but with no sensitive data. Hence a simple section of code who's purposeSo here is my attempt to echo out a full name from a databasewrite one:
With understanding that the users table contains a username, first name and last name, why are mappers convenient to use.
This is a very long winded way in getting data, and assuming that users aren't everything, but instead orders, payments, tickets, companies and more all have their corresponding mappers, it seems a waste not to create just one mapper and implement it everywhere in each class. This allows the folder structure to look a whole lot nicer and also means that code isn't repeated as often.
The example mapper looks the same in every case bar the table the data is being pulled from.
Therefore my question is. IsI am asking whether this how data mappers under the 'domain model mappers' should look like, and if not how could my code could be improved. Secondly is this model needed in all cases of needing to pull data from a database, regardless of the size of classgeneral, or should this model onlyand I am interested in particular whether it could be used whereoptimized the user.phpway I won't have to create a distinct mapper class in this case is very large.
Thank you in advance for the every entity, as they all helpseem identical to me, making a lot of duplicated code.
Is this the right way to make a DataMapper under the domain mapper model?
Hopefully i am asking this on the right stack exchange forum. If not please do let me know and I will ask somewhere else.
As I have self learned PHP and all programming in general, I have only recently found out about 'Data Mappers' which allows data to be passed into classes without said classes knowing where the data comes from. I have read some of the positives of using mappers and why they make it 'easier' to perform upgrades later down the line, however I am really struggling to find out the recommended way of using mappers and their layouts in a directory structure.
The way I have been using/creating mappers (as well as the file structure is as follows). The code below represents the real life use case but with no sensitive data. Hence a simple section of code who's purpose is to echo out a full name from a database:
With understanding that the users table contains a username, first name and last name, why are mappers convenient to use.
This is a very long winded way in getting data, and assuming that users aren't everything, but instead orders, payments, tickets, companies and more all have their corresponding mappers, it seems a waste not to create just one mapper and implement it everywhere in each class. This allows the folder structure to look a whole lot nicer and also means that code isn't repeated as often.
The example mapper looks the same in every case bar the table the data is being pulled from.
Therefore my question is. Is this how data mappers under the 'domain model mappers' should look like, and if not how could my code be improved. Secondly is this model needed in all cases of needing to pull data from a database, regardless of the size of class, or should this model only be used where the user.php class in this case is very large.
Thank you in advance for all help.
A DataMapper under the domain mapper model?
I have only recently found out about 'Data Mappers' which allows data to be passed into classes without said classes knowing where the data comes from.
So here is my attempt to write one:
I am asking whether this code could be improved in general, and I am interested in particular whether it could be optimized the way I won't have to create a distinct mapper class for the every entity, as they all seem identical to me, making a lot of duplicated code.
Is this the right way to make a sample DataMapper under the domain mapper model?
Let's assume we have a simple application whos purpose is to echo out a first name and last name of a user.
The way I have been using/creating mappers (as well as the file structure is as follows). The code below represents the real life use case but with no sensitive data. Hence a simple section of code who's purpose is to echo out a full name from a database:
Is this the right way to make a sample DataMapper under the domain mapper model?
Let's assume we have a simple application whos purpose is to echo out a first name and last name of a user.
The way I have been using/creating mappers (as well as the file structure is as follows):
Is this the right way to make a DataMapper under the domain mapper model?
The way I have been using/creating mappers (as well as the file structure is as follows). The code below represents the real life use case but with no sensitive data. Hence a simple section of code who's purpose is to echo out a full name from a database: