Note that there are some explanatory texts on larger screens.

plurals
  1. POData Mapper: Is my interpretation correct?
    primarykey
    data
    text
    <p>I'm trying to confirm now, what I believe about the Data Mapper pattern. So here we go:</p> <p><strong>Section A:</strong> A Data Mapper is a class which is used to create, update and delete objects of another Class. Example: A class called <code>Cat</code>, and a Data Mapper called <code>CatDataMapper</code>. And a database table called <code>cats</code>. But it could also be an xml file called <code>cats.xml</code>, or an hard-coded array called <code>cats</code>. The whole point of that Data Mapper is to free the Business Logic which uses the Cat class from thinking about "how to get an exisiting cat", or "how to save a cat", "where to save a cat". As a user of the Data Mapper it looks like a blackbox with well-defined methods like getCat(int id), saveCat(Cat catObject), deleteCat(Cat catObject), and so on.</p> <p><strong>Section B:</strong> First I thought it would be clever if Cat inherits from CatDataMapper, because calling such functions then is a bit more convenient. For example, methods like catWithId(int id) could be static (class method) and return an instance of a Cat, initialized with data from <em>anywhere</em>. And when I work with a cat object in my code, I could simply call myCat->save(); to store it whereever the Data Mapper will store it (don't care where and how, the Data Mapper hides this complexity from the user).</p> <p>In conclusion, I'm a little bit confused now ;) Do you think that <strong>Section A</strong> is valid for the Data Mapper pattern? And if I would do it additionaly as described in <strong>Section B</strong>, would that be bad? Why?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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