2

I'm a LAMP-stack dev who's been more on the JavaScript side the last few years and really enjoying the Model + Collection approach to data entities that BackboneJS, etc. uses. It's helped me organize my code in such a way that it is extremely portable, keeping all my properties and methods in the scope (model, collection, etc.) in which they apply.

One thing that keeps bugging me though is how to organize the next level up, the 'process layer' as you might call it, that can potentially operate on instances of either models or collections or whatever else. Where should methods like find() (which returns a collection) and create() (which returns a model) reside? I know some people would put a create() in the Collection prototype, but while a collection operates on models I don't think it's exactly right to create them. And while a find() would return a collection I don't think it correct to have that action within the collection prototype itself (it should be a layer up).

Can anyone offer some examples of any patterns that employ some kind of OOP-friendly 'process' layer? I'm sorry if this is a fairly well-known discussion but I'm afraid I can't seem to find the terminology to search for.

2
  • That kind of thing is going to happen mostly server-side, in the Business Logic Layer or Service Layer. Commented Aug 19, 2014 at 23:53
  • My question wasn't client/server-specific, in fact I'm actually asking it more for the server-side than client-side. Looking for a bit more of a specific answer though, what are the 'components' inside the service/business layer? Are they singleton classes, factories, etc.?
    – Dan
    Commented Aug 20, 2014 at 12:57

1 Answer 1

1

In Domain Driven Design (DDD) this kind of thing would be in a 'Repository'. The terminology used is to "rehydrate object(s) from the database".

For creation of objects, use a 'Factory' object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.