Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8343815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:10:41+00:00 2026-06-09T06:10:41+00:00

In my model layer I have data mappers, domain objects, and services (to liase

  • 0

In my model layer I have data mappers, domain objects, and “services” (to liase outside the model layer). I chose to implement a DomainObjectFactory and a DataMapperFactory, which has left me stuck on the DM<->DO relationship. Ideally the data mapper would return an instance (or an array of instances) of the related domain object for every method that performs a “get”/”read”, but the data mapper doesn’t have access to the domain object factory.

Without the factory pattern over the DM and DO, the autoloader could take over within the DM such that instances of the DO could be created. But how is this accomplished with a factory?

One possible solution I can think of would be to pass an instance of the related domain object to the data mapper method, e.g:

    $user = $this->domainObjectFactory->build('user');
    $mapper = $this->dataMapperFactory->build('userMapper');

    //Pass an [empty] user DO to the DM, which will be returned back
    $mapper->getById($someIDValue, $user);

This option seems very dirty, but it would work for single get methods. However it goes semantically off-the-rails when dealing with returning an array of domain objects, so clearly this isn’t the best way to accomplish this… Another option would be to allow the data mapper access to the domain object factory, but that would turn into a massive LOD/SRP violation.

In short: How can a data mapper access the domain object factory to be able to return domain objects?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:10:44+00:00Added an answer on June 9, 2026 at 6:10 am

    I solve it like this:

    $user = $this->domainObjectFactory->build('user');
    $mapper = $this->dataMapperFactory->build('userMapper');
    
    $user->setName('Foobar');
    $mapper->fetch( $user );
    // mapper acquires entries that are related to user with name `"Foobar"`
    // and loads it into the domain object
    

    The idea is that then retrieving data from storage, mapper uses the existing parameters of domain object as conditions. If you are dealing with a list of domain objects, you create a mapper with works with collections instead, and assign the condition(s) to that collection.

    Also, you might find this answer indirectly related to your issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a domain data model which returns a class such as the following:
I have data model classes that contain private fields which are meant to be
I have a Web Service ( model-layer ) which communicates with Database. This module
I am using a repository design with web applications (repository (data layer) exposing model
I am trying to model a simple domain by using DDD. Database layer is
I'm developing an application with a service layer that operates on a domain model.
We are using Hibernate as persistency layer and have complex object model. Without exposing
As we all know most apps have a data access layer, often using repository
Here's the architecture of my app: I have a data access layer in a
I have existing database and ADO Data services on top of it. Right now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.