Reuse the data CRUD methods in data access layer, but they are updated too quickly

I agree that we should put CRUD methods in a data access layer, However, in my current project I have some issues.

It is a legacy system, and there are quite a lot CRUD methods in some concrete manager classes.

People including me seem to just add new methods to it, rather than reuse the existing methods.

Because

  1. We don’t know whether the existing method is what we need
  2. Even if we have source code, do we really need read other’s code then make decision?
  3. It is updated too quickly. Do not have time get familiar with the DAO API.

Back to the question, how do you solve that in your project? If we say “reuse”, it really needs to be reusable rather than just an excuse.

The main problem would seem to be that the legacy interfaces are not understood and not trusted. It’s not possible to solve this problem by ignoring it – and adding more members ad-hoc is actively making it worse.

The bottom line is that interfaces to your classes should be clear, small, trusted, well-documented, and ideally only about a single responsibility (refer to the Single Responsibility Principle).

Techniques like refactoring can be used to move towards that ideal goal. Remember: it will take conscious effort to improve the situation.

Assuming that your organization has the right for to access and change the code, the right thing to do is to:

  1. Plan for missing activities in your project such as: source control, locating missing code, learning current system, etc.

  2. Find the source code for the system you are changing. Unless the application is trivial, it is most probably going to be useful specially if it is still in production.

  3. Study the schema and the source code well and plan to re-use. You may find information you don’t know such as filed dependencies that are not obvious or special business rules.

  4. Don’t write new code that is like the old code unless there is a major issue with the old code. You need to have a clear policy as why there are 2 different classes for Customer for example, otherwise, maintenance and testing will be hell.

I don’t understand your point (#3).

The only valid excuses to not re-use existing system’s code, INMO, is if you are migrating the system to use a new framework or can’t access the code for a technical or legal reason. A system must have internal order and proper structure, it can’t be a quality system if it looks like a college student’s room!

In a DAO you may return 3 columns from table A, joined with 2 columns from table B, etc. Maybe 4 tables are touched in a single transaction. It will be a necessity to create a new method for new functionality, even on existing tables. The possible permutations are endless. It is not possible to cover every database interaction with generic CRUD methods.

Actually it’s possible to cover every interaction with generic CRUD, but it would be like forcing a circle through a square shaped hole.

Usually some sort of framework provides generic CRUD access to the tables. The methods are often designed for working on 1 record at a time. If you fall within this scope, then use the generic CRUD methods. But you wouldn’t want to use these methods to update 5 million rows as they would literally perform 5 million separate updates. (they also tend to redundantly update all columns of the row, whether edited or not causing locking issues). You cannot use them for transactional functionality if they are non-transactional.

Just identify when to use the generic CRUD methods vs custom methods.

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