Jump to content

To factory or not to factory?

Go to solution Solved by Drongo_III,

Recommended Posts

I'm working on a new project and need to create DTOs for use in views (this is a Laravel project so MVC). The DTO will get created from subsets of values from 2 other models (Price, Quote). Obviously, it wouldn't be ideal to build the DTO from those models in multiple places so I want to seat that logic in a specific class.  I figure an approach is to use a factory - i.e. as a place to capture the creation of the DTO. But when I read into Factory Method and Abstract Factory  and Simple Factory this use case doesn't sound like it fits.

So my questions are:

  1. Is a factory the right pattern?
  2. If so, which flavour of factory would you suggest?
  3. Is this the way you would approach it?  I appeal to the more experienced minds here for some insight. I work alone so it's hard sometimes to figure out the right approach.




Edited by Drongo_III
  • Like 1
Link to comment
Share on other sites

  • Solution
13 hours ago, requinix said:

Need more details.

Or try from another angle. What kind of code do you want to write in order to get the data you need?

I actually dusted off my copy of Patterns of Enterprise Application Architecture and there was a chapter on DTOs.  In that chapter it  recommends using a 'DTO Assembler' which is an type of Mapper - i.e. an intermediary to keep the DTO ignorant of the Models that supply it's data.  And this seems to solve the very problem I'm trying to solve, I just didn't have a name for it and incorrectly thought 'factory must be what i need'.

Edited by Drongo_III
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.

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.