Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've been studying n-tier architectures as of late, particularly in VB.NET with Entity Framework and/or LINQ to SQL. I understand the basic concepts, but have been wondering about best practices in regard to triggering CRUD-type operations from user input/action. So, the arcitecture looks something like the following:

[presentation layer] -> [business layer] -> [data layer] -> (database)

Getting information from the database into the presentation layer is simple and abstracted. It's just a matter of instantiating a new object from the business layer, which in turn uses the data layer to get at the correct information. However, saving (updating and inserting), and deleting seem to require particular APIs on the relevant business objects. I have to assume this is standard practice, unless a business object will save itself on various operations (which seems inefficient), or on disposal (which seems like it just wouldn't work, or may be unwieldy and unreliable).

Should my "savable" business objects all implement a particular "ISavable" or "IDatabaseObject" interface? Is this a recognized (anti-)pattern? Are there other, better patterns I should be using that I'm just unaware of?

The TLDR question, I suppose, is How does the presentation layer trigger database changes?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

How does the presentation layer trigger database changes?

Well, presentation layer should not directly trigger changes in database layer. It should initiate call to the service layer, where your business logic should verify the request. Upon successful verification it should perform DB operation on entities/tables that it needs.

You may also look at this very useful pattern - Repository Pattern that may associate a behavior with the related data.

share|improve this answer
    
Right. So, all my business-layer classes should implement some sort of save method? –  Ryan Kinal Sep 28 '12 at 19:19
    
You may say like that, actually all your entities should have CRUD operations on them. You may use Repository pattern to easy your operations as well. Link is provided. –  Yusubov Sep 28 '12 at 19:21
1  
That makes a lot of sense. I like it. –  Ryan Kinal Sep 28 '12 at 19:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.