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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:49:20+00:00 2026-05-10T13:49:20+00:00

Say you have an application divided into 3-tiers: GUI, business logic, and data access.

  • 0

Say you have an application divided into 3-tiers: GUI, business logic, and data access. In your business logic layer you have described your business objects: getters, setters, accessors, and so on… you get the idea. The interface to the business logic layer guarantees safe usage of the business logic, so all the methods and accessors you call will validate input.

This great when you first write the UI code, because you have a neatly defined interface that you can trust.

But here comes the tricky part, when you start writing the data access layer, the interface to the business logic does not accommodate your needs. You need to have more accessors and getters to set fields which are/used to be hidden. Now you are forced to erode the interface of your business logic; now it is possible set fields from the UI layer, which the UI layer has no business setting.

Because of the changes needed for the data access layer, the interface to the business logic has eroded to the point where it is possible to even set the business logic with invalid data. Thus, the interface does not guarantee safe usage anymore.

I hope I explained the problem clearly enough. How do you prevent interface eroding, maintain information hiding and encapsulation, and yet still accommodate different interface needs among different layers?

  • 1 1 Answer
  • 3 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-10T13:49:21+00:00Added an answer on May 10, 2026 at 1:49 pm

    If I understand the question correctly, you’ve created a domain model and you would like to write an object-relational mapper to map between records in your database and your domain objects. However, you’re concerned about polluting your domain model with the ‘plumbing’ code that would be necessary to read and write to your object’s fields.

    Taking a step back, you essentially have two choices of where to put your data mapping code – within the domain class itself or in an external mapping class. The first option is often called the Active Record pattern and has the advantage that each object knows how to persist itself and has sufficient access to its internal structure to allow it to perform the mapping without needing to expose non-business related fields.

    E.g

    public class User {     private string name;     private AccountStatus status;      private User()     {     }      public string Name     {         get { return name; }         set { name = value; }     }      public AccountStatus Status     {         get { return status; }     }      public void Activate()     {         status = AccountStatus.Active;     }      public void Suspend()     {         status = AccountStatus.Suspended;     }      public static User GetById(int id)     {         User fetchedUser = new User();          // Lots of database and error-checking code         // omitted for clarity         // ...          fetchedUser.name = (string) reader['Name'];         fetchedUser.status = (int)reader['statusCode'] == 0 ? AccountStatus.Suspended : AccountStatus.Active;          return fetchedUser;     }      public static void Save(User user)     {         // Code to save User's internal structure to database         // ...     } } 

    In this example, we have an object that represents a User with a Name and an AccountStatus. We don’t want to allow the Status to be set directly, perhaps because we want to check that the change is a valid status transition, so we don’t have a setter. Fortunately, the mapping code in the GetById and Save static methods have full access to the object’s name and status fields.

    The second option is to have a second class that is responsible for the mapping. This has the advantage of seperating out the different concerns of business logic and persistence which can allow your design to be more testable and flexible. The challenge with this method is how to expose the name and status fields to the external class. Some options are: 1. Use reflection (which has no qualms about digging deep into your object’s private parts) 2. Provide specially-named, public setters (e.g. prefix them with the word ‘Private’) and hope no one uses them accidentally 3. If your language suports it, make the setters internal but grant your data mapper module access. E.g. use the InternalsVisibleToAttribute in .NET 2.0 onwards or friend functions in C++

    For more information, I’d recommend Martin Fowler’s classic book ‘Patterns of Enterprise Architecture’

    However, as a word of warning, before going down the path of writing your own mappers I’d strongly recommend looking at using a 3rd-party object relational mapper (ORM) tool such as nHibernate or Microsoft’s Entity Framework. I’ve worked on four different projects where, for various reasons, we wrote our own mapper and it is very easy to waste a lot of time maintaining and extending the mapper instead of writing code that provides end user value. I’ve used nHibernate on one project so far and, although it has quite a steep learning curve initially, the investment you put in early on pays off considerably.

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

Sidebar

Related Questions

Let's say I have my pizza application with Topping and Pizza classes and they
Let's say I have an existing application written in Java which I wish to
Say I have a third party Application that does background work, but prints out
Say I have default content on the left side of my application, which is
Let's say I wanted to have an application that could easily switch the DB
Let's say I have a simple ASP.NET MVC blog application and I want to
Let's say I have a container (std::vector) of pointers used by a multi-threaded application.
When creating a web application, and lets say you have a User object denoting
Let say I have application menus in a database with their icon images (binary
Lets say I have an intraweb application (written in Delphi 2010) with an iwEdit

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.