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 am writing a simple ASP.NET Web Forms application. I want to improve the code by implementing any design pattern with which abstraction is achieved and increases manageability and understandability.

Which pattern is recommended? Please also provide links to sample applications.

share|improve this question
1  
+1 to MVP pattern –  Yusubov Jun 30 '12 at 12:59
    
is it an enterprise level application? –  Yusubov Jun 30 '12 at 15:19
add comment

4 Answers 4

up vote 2 down vote accepted

You might consider using the Model-View-View model MVVM pattern. It is a derivative of MVC, but is designed / intended to be used in exactly the situation you describe. There is a wealth of information on the MSDN site if you don't feel like googling it.

MVVM facilitates a clear separation of the development of the graphical user interface 
(either as markup language or GUI code) from the development of the business logic or back 
end logic known as the model (also known as the data model to distinguish it from the view 
model). The view model of MVVM is a value converter[4] meaning that the view model is 
responsible for exposing the data objects from the model in such a way that those objects 
are easily managed and consumed. In this respect, the view model is more model than view, 
and handles most if not all of the view’s display logic (though the demarcation between 
what functions are handled by which layer is a subject of ongoing discussion[5] and 
exploration). The view model may also implement a mediator pattern organising access to the 
backend logic around the set of use cases supported by the view.
share|improve this answer
    
I read about ASP.NET Model View Presenter framework at codeplex. Is MVVM available for Web Forms through any implementation? –  RPK Jun 30 '12 at 11:54
    
MVP and MVVM are essentially the same. The Wikipedia article explains this too: MVP is the first derivative in this chain from MVC. Martin Fowler is credited with publishing the pattern and it deals with some of the challenges that a Controller can have in an event driven realm. MVVM was a refinement from there to take advantage of data binding between the view and view-model. –  GlenH7 Jun 30 '12 at 12:03
    
Most of the applications I saw use Repository Pattern alone. What is reason? –  RPK Jun 30 '12 at 12:07
1  
The repository pattern is a little faster to implement and not as heavy as MVP / MVVM. The View is hitting the model directly instead of having an intermediary layer. Compared to MVP / MVVM it will be faster to implement with less code to write. OTOH, it will be more brittle because it is tightly coupled to the model / data access layer. Repository Pattern would possibly work for the circumstances you described, but if your project grows, you'll wish you had the intermediary Presenter / VM layer. –  GlenH7 Jun 30 '12 at 12:54
add comment

With ASP.NET Web Form, you typically use the Model View Presenter pattern.

GlenH7 mentioned on his answer about MVVM, while it is an elegant pattern, ASPX Webform just doesn't have great support for that. MVVM is more popular in the WPF world.

share|improve this answer
add comment

The one thing you need to avoid at all costs is the WebForms anti-pattern of putting logic in your code-behind. Whether you use MVP or a flavor of that or not, your code-behind files should be very sparse for the sake of your sanity.

share|improve this answer
1  
At present my code-behind is tightly couple with the logic. And this is the biggest mistake Web Form developers often do. –  RPK Jun 30 '12 at 12:14
add comment

Short answer is : look at MVP pattern that avoids potential code-behind asp.net forms issue by loosely coupling (de-coupling) your view and logic.

You may also want to go one step further and look at comparison MVC, MVP, ASP.NET.

The following posts are good entry points and examples:

share|improve this answer
add comment

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.