Go Back   SitePoint Forums > Forum Index > Program Your Site > .NET
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Nov 28, 2009, 05:44   #1
imaginekitty
SitePoint Guru
 
imaginekitty's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 804
Programming in "layers" [ASP.NET MVC]

I've been reading up on MVC and I'm starting to get it but there are some ideas that are still foreign to me. When it is said that a programming layer is beneath another layer how is that defined? Are certain layers inherently above or below others? Is it purely conceptual or is it based on a defined architecture?
imaginekitty is online now   Reply With Quote
Old Nov 28, 2009, 18:17   #2
Serenarules
SitePoint Wizard
 
Serenarules's Avatar
 
Join Date: Dec 2002
Posts: 1,117
I'm not so sure now that I'm the one the should be commenting on this, as I've had some resurgence of self-questioning lately, but I'll give you the run down, from top to bottom:

Web / UI Layer: the mvc app
- Some people actually move controllers to it's own class library as well.

Presentation Layer: these are thin classes designed to package data for sending to views.

Logistics Layer: service interfaces and implementations, specification pattern objects, etc
- Define anything here that your app will use to apply logic or processing to data before sending it to the persistence layer.

Persistence Layer: repository implementations
- This defines how your data actually gets stored. It could be sql, linq, whatever. It could be MySql, Oracle, whatever.

Domain Layer: entities, value objects, and repository interfaces
- This defines the look of you app without defining how certain things get done.

Where you put things like extension method classes, custom controllers and other things is up to you. Really, where ANYTHING goes, organizationally speaking, is up to you. You can plop it all right into MyProject.models and it'll still be right as long as you keep things correct conceptually.

Short answer: it's a conceptual thing, but good physical organization helps in maintaining that.
Serenarules is offline   Reply With Quote
Old Nov 28, 2009, 18:22   #3
imaginekitty
SitePoint Guru
 
imaginekitty's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 804
Thanks, man! Exactly what I was looking for.
imaginekitty is online now   Reply With Quote
Old Nov 29, 2009, 03:35   #4
NightStalker-DNS
SitePoint Wizard
 
NightStalker-DNS's Avatar
 
Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 1,828
I agree with Seren, explained very well. I would just swop the persistance and domain layer around on your list. lol. That has nothing to do with you app, just to read in the list. lol.

At the end of the day it is up to you and how far you want to go with layering. Sometimes if I am really in a hurry with ridiculous deadlines, etc. I only have 2 layers. Presention/UI layer in 1 and Domain/Persistence layer in another.
NightStalker-DNS is offline   Reply With Quote
Old Nov 29, 2009, 05:53   #5
imaginekitty
SitePoint Guru
 
imaginekitty's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 804
Trying out MVC is making me think more clearly in at least these three layers. Some of it makes me think "that makes complete sense" and some of it makes me want to smash my head on the floor.

I know what you're saying about deadlines, too. I've put out a quickie before and then felt bad and went back to refactor but not to the level that MVC seems to want.

I think I shouldn't have waited so long to get into it.
imaginekitty is online now   Reply With Quote
Old Nov 29, 2009, 11:06   #6
NightStalker-DNS
SitePoint Wizard
 
NightStalker-DNS's Avatar
 
Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 1,828
I have a sorta love hate relationship with MVC. I love it, with regards to the way its put together and so forth, but hate it coz it feels like a step back in time from asp.net websites. No code behind, no databinding of server side controls. The not code behind is good, as it forces you to stick to strict standards, but its the lack of databinding that i miss. lol
NightStalker-DNS is offline   Reply With Quote
Old Nov 29, 2009, 12:13   #7
Serenarules
SitePoint Wizard
 
Serenarules's Avatar
 
Join Date: Dec 2002
Posts: 1,117
At first, I would've agreed with you completely, but the more I worked with MVC, the more I realised that with the right patterns in place, the methodologies and conventions are just as strict. The practice that convinced me to use MVC over WebForms (and therefore codebehind) is separation of concerns. The MVC framework, and it's related patterns, promotes separation of concerns and makes the final code more readable and testable. Please note that these same practices can be used in a webforms app, however, you are still left with a mixture of logic and presentation, which some argue is a bad idea. Of course, this up to each person to determine. I've always had the "do what works" attitude.
Serenarules is offline   Reply With Quote
Old Nov 29, 2009, 22:25   #8
NightStalker-DNS
SitePoint Wizard
 
NightStalker-DNS's Avatar
 
Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 1,828
Yea, that what I said. MVC is more strict and has great structure. Thats why I like it. The only thing I do not like is no Repeater, gridview, etc. But you are right. The code behind does almost promote mixing of the UI and Business layer
NightStalker-DNS is offline   Reply With Quote
Old Nov 29, 2009, 23:04   #9
Serenarules
SitePoint Wizard
 
Serenarules's Avatar
 
Join Date: Dec 2002
Posts: 1,117
Oops, I think I read your previous post too quickly and missunderstood. Ah well. have you looked into partials? I am going to assume you have as you're pretty well versed. Is there any reason you would prefer a data bound control over using a RenderPartials(string partialName, IEnumerable models) method?
Serenarules is offline   Reply With Quote
Old Nov 30, 2009, 04:06   #10
dhtmlgod
ALT.NET - because we need it
silver trophybronze trophy
 
dhtmlgod's Avatar
 
Join Date: Jul 2001
Location: Scotland
Posts: 5,149
I think of "layers" in a Mvc application in a different way than I did with WebForms. This blog post sums up how I approach it: http://jeffreypalermo.com/blog/the-o...ecture-part-1/
dhtmlgod is offline   Reply With Quote
Old Nov 30, 2009, 05:06   #11
Serenarules
SitePoint Wizard
 
Serenarules's Avatar
 
Join Date: Dec 2002
Posts: 1,117
One thing you'll want to ask yourself too is: if I were to hand these libraries over to another team, and they decide to build a different persistence layer, or a different ui, would they be able to simply swap it out?

I usually build my domain entities and persistence interfaces into an assembly of it's own, my mapping and persistence implementations into it's own as well, and in addition, any application services get their own layer. The reason is so that any one of them can be swapped, based on the fact that any replacements will be based on the same interfaces. So if a user doesn't like my linq to sql implementation, they can swap it out for an sql client based one, or one that hits an oracle db.
Serenarules is offline   Reply With Quote
Old Nov 30, 2009, 06:15   #12
imaginekitty
SitePoint Guru
 
imaginekitty's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 804
Quote:
Originally Posted by dhtmlgod View Post
I think of "layers" in a Mvc application in a different way than I did with WebForms. This blog post sums up how I approach it: http://jeffreypalermo.com/blog/the-o...ecture-part-1/
That's given me much to think about.

Here is another mention of "web site size":
Quote:
... This architecture is not appropriate for small websites. ...
Just as I've asked in the past about Entity Framework vs. Linq to Sql, how do you define the size of a web site? What is large and what is small??
imaginekitty is online now   Reply With Quote
Old Nov 30, 2009, 10:48   #13
NightStalker-DNS
SitePoint Wizard
 
NightStalker-DNS's Avatar
 
Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 1,828
Quote:
Originally Posted by Serenarules View Post
Oops, I think I read your previous post too quickly and missunderstood. Ah well. have you looked into partials? I am going to assume you have as you're pretty well versed. Is there any reason you would prefer a data bound control over using a RenderPartials(string partialName, IEnumerable models) method?
Yea, I have looked at that, and it is great, i just prefer the databinding way of doing it. Just guess some old habits die hard. lol

Quote:
Originally Posted by NAWA-mark View Post
Just as I've asked in the past about Entity Framework vs. Linq to Sql, how do you define the size of a web site? What is large and what is small??
A small website is anything 800px wide or less and big site above that. hahaha. Sorry, couldnt help myself.

Well, it will basically come down to your own discretion. Of how complex and how man facets your website will have. Are you going to take more time building the layers than the entire site? It is very hard to give a definitive answer to this.

I also have done many a project, where I receive a brief. Very simple site, so use simple tech. Only to have it evolve into something so much more.
NightStalker-DNS is offline   Reply With Quote
Old Nov 30, 2009, 11:05   #14
imaginekitty
SitePoint Guru
 
imaginekitty's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 804
Quote:
Originally Posted by NightStalker-DNS View Post
... I also have done many a project, where I receive a brief. Very simple site, so use simple tech. Only to have it evolve into something so much more.
That's just it, it always turns into more than intended.
imaginekitty is online now   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 13:33.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved