Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4246260
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:56:58+00:00 2026-05-21T03:56:58+00:00

As I get it, the model in is DDD divided into these tiers: Storage

  • 0

As I get it, the model in is DDD divided into these tiers:

  • Storage (database, file, cache …)
  • Mapper (takes data from the storage)
  • Repository (manages data for a single entity type, can use different mappers)
  • Entity (a simple data container, independent of other tiers)
  • Service (handles business logic like Get the 5 newest posts ordered alphabetically by title, uses the Repository)

So, this is are the 5 tiers (please correct me if I misunderstood something). And the question is:

If I have business logic that is related to a single entity, should I implement it in the Entity, or in the Service?

For example, if I have a post and want to retrieve all its comments that are approved, should it be Post.getApprovedComments (entity) or CommentsService.getApprovedCommentsForPost(Post post)?

(No, it’s not right to use post.getComments().filter(comment -> comment.approved), because that moves business logic out of the Model. Just in case someone asks.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T03:56:59+00:00Added an answer on May 21, 2026 at 3:56 am

    So, this is are the 5 tiers (please correct me if I misunderstood something).

    I think often people will group Data Storage, ORM and the Repository in one ‘layer’ as far as your code is concerned. Also, don’t forget about presentation.

    If I have business logic that is
    related to a single entity, should I
    implement it in the Entity, or in the
    Service?

    Yes, if it is behavior related to the entity then it should reside within the Entity. Entities shouldn’t just be simple data containers, rather the Entity/Model layer should encapsulate both data-structure and behavior related to your business model. In this way, if you need to reuse the Model layer in another app, you dont have to dig around to find the related behavior that you stuck in other layers.

    For example, if I have a post and want to retrieve all its comments that are approved, > should it be Post.getApprovedComments (entity) or > CommentsService.getApprovedCommentsForPost(Post post)?

    Difficult to say without knowing more about your architecture and ORM. I’d probably go with the Post.. route (comments should be a collection on the Post entity), and then getApprovedComments could be a simple linq query or such. The Service based approach you suggest doesn’t look very OOP to me.

    (No, it’s not right to use post.getComments().filter(c -> comment.approved), because that moves business logic out of the Model. Just in case someone asks.)

    I’m not entirely sure I agree with you here. For something this simple, some might think it acceptable.

    I’d add that:

    Service (handles business logic like Get the 5 newest posts ordered alphabetically by title, uses the Repository)

    …is in my opinion not a good example of a service. The service layer is doing nothing in this example – this should just be a query method defined in the PostRepository.

    Hope some of that helps a little…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm implementing a custom BCS Model to get data from a backend system. As
My model inherits from an interface: public interface IGrid { ISearchExpression Search { get;
Have checked some backbone.js tutorials and can't understand how to get model id from
aaa bbb ccc ddd When I using copy the above lines from a file
I have a strongly typed view. I get model passed into the view and
How can i get model name from model instance. For e.x. $model=new State; here,
I get a model object, change an attribute, save it and it still has
We are trying to get the Model-View-Presenter pattern used on (virtually) all new dev
I'm wondering is there a difference in terms of computing cost for the Model.get(keys)
Trying to query a 'Favorites' model to get a list of items a user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.