Should I pass an object or values?

Let’s say I have a model that has ‘purchase’ method. The purchase method should take care of purchasing a product.

Signature of purchase

public function purchase($token, Model_Member $member, Model_Product $product, Model_Recipient $recipient);

To call this method, I need to make $member, $product, and $recipient in my controller. Is it considered a better approach to pass an array of values to the purchase so that purchase can make those required objects like below?

public function purchase($token, $member_id, $product_id, array $recipient);

in this case, purchase should pull up a member record from the database and make a model of it.

What’s the better approach?

1

Is it considered a better approach to pass an array of values to the
purchase so that purchase can make those required objects like below?

In general, I would say, no. But, like everything it depends.

If your domain doing the purchasing is significantly complex, IMHO, it is better to map all data into structures that the domain understands (so in your case, the entities) and then call purchase.

This does a couple of beneficial things.

First, it means that the core business logic (purchasing) does not need the concern of how to hydrate data into objects. In other words, the domain entities do not need references to repositories.

Second, it means that you can map from many sources (database, web services, file systems) before calling the business domain. So, this sets up a nice separation of concerns around the core logic of your application.

For more on this. I recommend reading through the Onion Architecture series of blog posts.

Now, for the “It depends” part:
Every time that you add a logical layer to your application, you add complexity. In this case, you add the necessity to map into these domain objects before calling purchase. So, if you are performing simple CRUD operations or forwarding on calls to some web service, then you probably don’t need to incur that cost.

0

Well the way I do it is like this:
The Controller:

  • Should be responsible for interacting with the view and choosing the
    appropriate Application service.
    So read the input from the request object and create the appropriate
    Application service.

The application service:

  • Should be responsible for modeling your use case (i.e. your application logic), but holds no business logic. It orchestrates the application, but does no work itself.
    The raw input passed from the controller is mapped to objects in this layer. Any domain service required is created in this layer and the appropriate method is invoked on this service.

The Domain Service, Entities and Value Objects:

  • Should be responsible for modelling your domain logic and doing the actual work.

So in your case create the objects in the application service then pass them to the appropriate Domain service/entity/value object.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Should I pass an object or values?

Let’s say I have a model that has ‘purchase’ method. The purchase method should take care of purchasing a product.

Signature of purchase

public function purchase($token, Model_Member $member, Model_Product $product, Model_Recipient $recipient);

To call this method, I need to make $member, $product, and $recipient in my controller. Is it considered a better approach to pass an array of values to the purchase so that purchase can make those required objects like below?

public function purchase($token, $member_id, $product_id, array $recipient);

in this case, purchase should pull up a member record from the database and make a model of it.

What’s the better approach?

1

Is it considered a better approach to pass an array of values to the
purchase so that purchase can make those required objects like below?

In general, I would say, no. But, like everything it depends.

If your domain doing the purchasing is significantly complex, IMHO, it is better to map all data into structures that the domain understands (so in your case, the entities) and then call purchase.

This does a couple of beneficial things.

First, it means that the core business logic (purchasing) does not need the concern of how to hydrate data into objects. In other words, the domain entities do not need references to repositories.

Second, it means that you can map from many sources (database, web services, file systems) before calling the business domain. So, this sets up a nice separation of concerns around the core logic of your application.

For more on this. I recommend reading through the Onion Architecture series of blog posts.

Now, for the “It depends” part:
Every time that you add a logical layer to your application, you add complexity. In this case, you add the necessity to map into these domain objects before calling purchase. So, if you are performing simple CRUD operations or forwarding on calls to some web service, then you probably don’t need to incur that cost.

0

Well the way I do it is like this:
The Controller:

  • Should be responsible for interacting with the view and choosing the
    appropriate Application service.
    So read the input from the request object and create the appropriate
    Application service.

The application service:

  • Should be responsible for modeling your use case (i.e. your application logic), but holds no business logic. It orchestrates the application, but does no work itself.
    The raw input passed from the controller is mapped to objects in this layer. Any domain service required is created in this layer and the appropriate method is invoked on this service.

The Domain Service, Entities and Value Objects:

  • Should be responsible for modelling your domain logic and doing the actual work.

So in your case create the objects in the application service then pass them to the appropriate Domain service/entity/value object.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Should I pass an object or values?

Let’s say I have a model that has ‘purchase’ method. The purchase method should take care of purchasing a product.

Signature of purchase

public function purchase($token, Model_Member $member, Model_Product $product, Model_Recipient $recipient);

To call this method, I need to make $member, $product, and $recipient in my controller. Is it considered a better approach to pass an array of values to the purchase so that purchase can make those required objects like below?

public function purchase($token, $member_id, $product_id, array $recipient);

in this case, purchase should pull up a member record from the database and make a model of it.

What’s the better approach?

1

Is it considered a better approach to pass an array of values to the
purchase so that purchase can make those required objects like below?

In general, I would say, no. But, like everything it depends.

If your domain doing the purchasing is significantly complex, IMHO, it is better to map all data into structures that the domain understands (so in your case, the entities) and then call purchase.

This does a couple of beneficial things.

First, it means that the core business logic (purchasing) does not need the concern of how to hydrate data into objects. In other words, the domain entities do not need references to repositories.

Second, it means that you can map from many sources (database, web services, file systems) before calling the business domain. So, this sets up a nice separation of concerns around the core logic of your application.

For more on this. I recommend reading through the Onion Architecture series of blog posts.

Now, for the “It depends” part:
Every time that you add a logical layer to your application, you add complexity. In this case, you add the necessity to map into these domain objects before calling purchase. So, if you are performing simple CRUD operations or forwarding on calls to some web service, then you probably don’t need to incur that cost.

0

Well the way I do it is like this:
The Controller:

  • Should be responsible for interacting with the view and choosing the
    appropriate Application service.
    So read the input from the request object and create the appropriate
    Application service.

The application service:

  • Should be responsible for modeling your use case (i.e. your application logic), but holds no business logic. It orchestrates the application, but does no work itself.
    The raw input passed from the controller is mapped to objects in this layer. Any domain service required is created in this layer and the appropriate method is invoked on this service.

The Domain Service, Entities and Value Objects:

  • Should be responsible for modelling your domain logic and doing the actual work.

So in your case create the objects in the application service then pass them to the appropriate Domain service/entity/value object.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật