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

  • Home
  • SEARCH
  • 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 90545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:53:24+00:00 2026-05-10T22:53:24+00:00

I am in the process of refactoring our BI layers to make our code

  • 0

I am in the process of refactoring our BI layers to make our code more ‘loosely coupled’ and I was interested to hear what you guys thought might be interesting improvements to make?

At present, our API is something like the following:-

// Fetch a collection of objects ProductCollection prods = Product.GetProducts();  // Load an individual object, make change and save it back Product p = new Product(); if(p.Load(productID)) {     p.Name = 'New Name';     p.Save(); } 

As you can see, our methods for fetching collections of objects/loading individual objects and saving changes are all built into the ‘Model’ class. Each of our Model classes inherits from an ObjectBase base class which includes DB access functions and change tracking so when someone changes a value through a property the object is automatically marked dirty and notifications are fired to whatever object (UI) has subscribed to those events.

What I would like to do is use the ‘Repository pattern’ so that we can abstract the Database implementation away from the Model. However, much of the code I have been looking at seems to suggest that the ‘Model’ class should not contain any intelligence and should just be a container for data. Instead, the logic should be applied through the use of services. Does this then mean to accomplish the above I would need to do something like

List<Product> prods = ProductService.GetProducts();  Product p = ProductService.GetSingleProduct(productID); p.Name = 'New Name';  ProductService.SaveProduct(p); 

This seems a more complex way of doing it and makes it harder to encapsulate functionality within business objects.

Can someone explain why this is a better way of doing it or maybe have I misunderstood the concepts?

Thanks

James

  • 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. 2026-05-10T22:53:25+00:00Added an answer on May 10, 2026 at 10:53 pm

    Your current API is an implementation of the Active Record Pattern. This pattern tends to work fine when the object model used in the code is a one-on-one match with the database model. Another advantage is that tooling exists to generate these classes,including the persistence code, and database tables .

    The alternative you suggest is the Repository Pattern. As you already mention implementing this is a bit more complex, but has several advantages. Since you can implement any kind ORM tool you’re not limited to one-on-one mappings, but can implement more complex mappings where the object model can be different from the database model. So you don’t have to force an object model in the database or the other way around. However the more complex mappings, other than one-on-one can’t be generated and require some

    Another advantage is that you can create tests more easily, because you can create a Mock repository that doesn’t even require a database.

    Using the Repository Pattern you also separate the model from the persistence logic.

    In both situations it’s possible to write the persistence methods in a generic fashions so that the persistence code is generic a doesn’t need to know about a specific object that needs to be persisted. This is obvious for the Active Record Pattern since all these objects implement save, delete, update, etc.. For the the Repository Pattern you can also use ORM tools that work on any object so that code like this is possible:

    Repository.Save(ObjectOfAnyType); 

    ObjectOfAnyType can be anything as long as the ORM tool has some mapping defined/implemented for the type of the object.

    So you choose, do you want or need these advantages at the cost of a little added complexity. Or does the simplicity of the Active Record Pattern suffice.

    I always tend to use the Repository Pattern, but have used the Active Record Pattern on occasion, mostly for quick prototyping.

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

Sidebar

Related Questions

I'm in the process of refactoring some code which includes moving folders around, and
We are in the process of refactoring some code. There is a feature that
We are currently in the process of refactoring our site and we have decided
I'm in the process of refactoring our SpecFlow-implemented BDD tests. As part of this
Scenario: I am in the process of refactoring one of our applications to use
I have made a major refactoring of some code, and in the process I
I'm in the process of refactoring a project. I've got an entire subfolder which
I'm in the process of refactoring an application and I've decided to use a
So I'm refactoring a legacy codebase I've inherited, and in the process I found
We're in the process of redesigning the customer-facing section of our site in .NET

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.