design-patternsdomain-driven-designstrategy-patternservice-object

Are service object, transaction script and strategy design patterns the same?


I couldn't find any definition of the Service Object design pattern.

The Transaction Script design pattern

Organizes business logic by procedures where each procedure handles a single request from the presentation.

The Strategy design pattern

Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

Are they similar/equal?


Solution

  • This is the definition of the Service layer pattern: http://martinfowler.com/eaaCatalog/serviceLayer.html

    The service layer describes the system's use cases. These use cases are implemented in a Transaction Script manner. However, the Transaction Script pattern is a different beast - it is a way of organizing the system's business logic. So although they are similar, the intentions are different. You can implement the business logic as Active Record or Domain Model, but the Service Layer, will still resemble a transaction script.

    The strategy pattern is intended to encapsulate interchangeable algorithms, that are used inside of the system's use cases.

    I highly recommend reading the classic "Patterns of Enterprise Application Architecture" book to get a good grasp of these patterns.