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 4326932
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:28:04+00:00 2026-05-21T09:28:04+00:00

What would be the drawback (in terms of testability for example) to the following

  • 0

What would be the drawback (in terms of testability for example) to the following approach which intends to get the best from Active Record pattern and Repository pattern ?

Each persistent object exposes save() and delete() method, but no static methods to load itself, or to load a list of similar objects : loading from upper layers is done by directly calling a repository, to avoid static methods in persistent objects.

The “save()” and “delete()” methods are only facades, they are delegated to the repository.

Is testability really a concern with this approach ? Even with pure Active Record approach : are there information systems where database logic represents only a small part of the whole business logic, and where it would be interesting to mock the database access ?

EDIT : This approach needs that persistent objects inherit from an AbstractPersistentObject which implements “save()” and “delete()”, and it prevents business inheritance, but I read it was better to avoid business inheritance, and to replace it with composition, so it may be an advantage, and not a drawback…?

EDIT2 : Maybe this article will explain better which issues I am trying to solve : http://moleseyhill.com/blog/2009/07/13/active-record-verses-repository/

  • 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-21T09:28:05+00:00Added an answer on May 21, 2026 at 9:28 am

    There are two things that raise some concern. The first one is this quote (emphasis mine):

    […] are there information systems where database logic represents only a small part of the whole business logic, and where it would be interesting to mock the database access?

    Are you putting business logic in your database? If so: don’t do it, it makes it very hard to mock your database. You’d have to duplicate (and maintain!) all of the business logic from the database to your mocks, otherwise your tests are useless.

    But how do you know if the mocks correctly implement the business logic? You could write unit tests for your mocks, or reuse the unit tests of your database (you do have them, right?), but that’s an approach I’d try to avoid at all costs! Let me repeat: don’t ever (have to) write unit tests for your mocks. If you find yourself in such a situation, take a few steps back and review your design, because there’s something very wrong.

    Putting business logic in the database will only create unnecessary coupling between your model and the database, and immensely complicate your testing layer. Separation of concerns is key here: the model focuses on business logic only and the database focuses on persistence only, nothing else.

    Which brings me to my next concern: why do you need save() and delete() methods, which are persistence-related, on your domain model? Persistence doesn’t belong in the domain model.

    I know, you said that these methods will delegate to a repository, so the domain model (hopefully) doesn’t contain the actual persistence logic. But how does it know which repository it should delegate to?

    If you are calling a service locater in the save() method, you’re making it impossible to save the entity to multiple repositories. You’re also hiding the dependency on the repository from the caller, which I consider to be a bad thing.

    To solve these issues, you could pass a repository instance to the save() method, like this:

    public class Foo extends AbstractPersistentObject {
        public void saveTo(IFooRepository repository) {
            repository.save(this);
        }
    }
    

    But a method like this implies that the caller already has a repository instance, so he might as well call the save() method directly on the repository. Any persistence methods on the domain model would be obsolete.

    Perhaps I’m oversimplifying your problem. What is it you are trying to achieve? Do you only want the entity.save() syntax, or are you trying to solve a bigger problem?

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

Sidebar

Related Questions

Which of the following would you say is the best way to go when
I would like to find out which strategy is the best for links, forms
Would the following SQL remove also the index - or does it have to
Would it be possible to write a class that is virtually indistinguishable from an
Almost all of the applications I write at work get their data from a
One significant drawback of CSS is that one can't use variables. For example, I'd
I would like to store equivalences from Connected-component labeling algorithm . It's basically making
I would like to create a table which has column like title,target and I
We would like to change a web site from version 1.1 to 2.0.50727 during
I have an iterable of entries on which I would like to gather some

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.