Service layer coupling

Posted by Justin on Programmers See other posts from Programmers or by Justin
Published on 2013-11-05T06:16:29Z Indexed on 2013/11/05 10:11 UTC
Read the original article Hit count: 235

I am working on writing a service layer for an order system in php. It's the typical scenario, you have an Order that can have multiple Line Items. So lets say a request is received to store a line item with pictures and comments. I might receive a json request such as

{ 
    'type': 'Bike',
    'color': 'Red',
    'commentIds': [3193,3194]
    'attachmentIds': [123,413]
}

My idea was to have a Service_LineItem_Bike class that knows how to take the json data and store an entity for a bike.

My question is, the Service_LineItem class now needs to fetch comments and file attachments, and store the relationships. Service_LineItem seems like it should interact with a Service_Comment and a Service_FileUpload. Should instances of these two other services be instantiated and passed to the Service_LineItem constructor,or set by getters and setters? Dependency injection seems like the right solution, allowing a service access to a 'service fetching helper' seems wrong, and this should stay at the application level.

I am using Doctrine 2 as a ORM, and I can technically write a dql query inside Service_LineItem to fetch the comments and file uploads necessary for the association, but this seems like it would have a tighter coupling, rather then leaving this up to the right service object.

© Programmers or respective owner

Related posts about php

Related posts about dependency-injection