At what point does data accessmanipulation logic becomes business logic?

Consider a service which updates PersonDetail tables in database. I am Using EF which maps the table to this Entity. When a record is updated, it is not actually updated but a new record is created and old one is made history by setting HistoryCode to 0

Class PersonDetail
{
  int age;
  Date birthDate;
  DateTime effectiveDate;
  int sequenceNumber; //An incremental number.
  int HistoryCode; //0 represents history record and 1 current record
}

Now we have a service that updates the person details

if(newPersonDetail.effectiveDate < currentPersonDetails.effectiveDate)
{
  //update sequence number of currentPersonDetails by 1
  //insert a new Person Details record and assign its sequenceNumber as the sequence number    
  //of currentPersonDetails and HistoryCode as 0 to represent this is an history record
}
else
{
   //Make the currentPersonDetails HistoryCode to 0 from 1
   //Insert a newPersonDetail with sequence number incremented by 1 and HistoryCode set to 0
}

Logic? I am trying to move the data-access logic out of service layer to repository layer but not able to clearly figure out what part of this is considered as business logic and what is considered as Data Access logic.

The PersonDetail class is part of the data access. The service that updates PersonDetail is business logic. Note that, if you don’t actually need this separation (i.e. you won’t need to transplant the service layer to some other program, independently of the data access), it may not matter (you’re coupled to the data layer anyway, due to the presence of the POCO’s).

Although it’s not a very satisfactory answer, pretty much as soon as you introduce a condition (if, switch, etc.) into your data layer code, you’re technically mingling business logic and data access.

The reason it’s not very satisfying is that this implies that data access code is pretty dumb — it handles C.R.U.D. behaviors only. That’s why ORM emerged — it took that brain dead C.R.U.D. stuff off our plates.

So, now, you have to clarify what you mean by “data access” layer. A lot of times systems will be somewhat sophisticated and they’ll have something called “a data access layer” that’s really a combination of data access and very fundamental business logic. For example, it would make sure that you can’t commit a “car” to a database without “wheels”. Technically that’s business logic, but it’s so low-level, that it goes along with the data access layer code (often implemented on ORM).

When dealing with the data access layer code, you can think of the following:

  • Think of a persister, something that does operations on the data in the underlying persistence layer, such as save, delete, and update operations.

  • POJOs that represent the records in the tables are part of the DAL.

  • Every thing that depends on and queries that layer directly in order to use the persisted objects in operations can be classified as BL.

  • This should be a one way relation of course, BLL layer should depend on DAL and not the opposite.

Now the second code snippet you provided

if(newPersonDetail.effectiveDate < currentPersonDetails.effectiveDate)
{
  //update sequence number of currentPersonDetails by 1
  //insert a new Person Details record and assign its sequenceNumber as the sequence number    
  //of currentPersonDetails and HistoryCode as 0 to represent this is an history record
}
else
{
   //Make the currentPersonDetails HistoryCode to 0 from 1
   //Insert a newPersonDetail with sequence number incremented by 1 and HistoryCode set to 0
}

can be classified as BL if its true in some cases, but can be pushed to the DAL in case this is true whenever you are updating a record.

In some other cases, BL deals directly with the persistence layer for performance reasons, but this depends on what the application does.

1

Your question cannot be answered in general, but your example shows one thing : difference between business logic or requirement and implementation of that business logic.

In your example, but business requirement might be “Always keep history of changes to all Personal details.” Just because it is implemented as flag inside table and not separate table or some other way is implementation detail. Your business analyst doesn’t need to know how this history tracking is implemented. So the code in your case can be described as “manipulation logic, that implements a business requirement”.

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