Design Pattern, layers and cells.

Necuno

Court Jester
Joined
Sep 27, 2005
Messages
58,566
Reaction score
3,437
in a simplest example, normally one would have

  1. interface
  2. code io
  3. data base io

where as the user interacts with the interface, the interface in turn with code io and where needed code io with data base io. hence the 3 layerd system is born.

my question however is what other or better ways of doing this is there apart from these
  • layered model with one class for all database needs or
  • "objects to objects" instead of one massive data io class with all the calls in it, one object does data calls spesifically for its needs and populates the other related object (ea, studentDataObject and studentCarrerObject where as the data object gets or saves the student data. also can return a populated studentCarrierObject with for example say name and number to be used by the code and so on)

(i hope some of this makes sense :D)
 
Last edited:
UPFRONT DISCLAIMER: Long post to follow. Made sense when I typed it, but I didn't re-read afterwards... :p

Well, how I usually design is as follows:
  • Database Layer
    An assembly dedicated to performing database calls. I usually have a base-class which manages the connection to the database itself, as well as any exception handling. This class also exposes methods to perform various calls to the database, i.e. "Update calls" (insert / update / delete) and "Getter calls" (returning datasets, tables, scalars or return values). For each business entity in the system, I then have a separate database class, inheriting from the base class. This derived class then interacts with the necessary tables via stored procedures - NEVER direct queries.
  • Business Layer
    An assembly dedicated to handling all business logic and representing all necessary business entities in object form. The business layer is the ONLY assembly that references the Database Layer. I create strongly-typed objects with the necessary member variables, properties and methods so as to correctly represent them in context of the business. I also make sure that the objects can be correctly serialized to XML (i.e. that the necessary properties will be correctly serialized to attributes, elements, enum or even ignored), so that web services utilizing this assembly will always return the correct serialized XML representation of the objects.
  • Interface / Presentation Layer
    Finally, the Interface Layer just handles the display and user interaction with the business entities. The Interface Layer only contains a reference to the Business Layer assembly. I prefer working with objects, as the properties are a lot more intuitive than trying to bind to column names in a data table. Also, calling the "Update" method for a specific object gives you much more control over what goes in the database, instead of just committing a dataset's contents to the database and hoping for the best. When working with a web application, I prefer to serialize the business objects to XML and transform it with the appropriate XSLT file. It makes for a nice, dynamic solution that you can easily adapt without having to rebuild and -deploy a complete solution.

Of course, then you can always follow the MVC / MVP route. In terms of ASP.NET MVC, its still (iirc) in a bit of a beta-phase, so I would personally wait a while and see how it pans out commercially (Stack Overflow is a nice example of a commercial ASP.NET MVC site though). I enjoy implementing a bit of a 3-tier / MVC hybrid solution though - I associate each business entity with a specific XSLT file, with a "RenderToHtml" method transforming the object's serialized XML with the specified XSLT file. You are still stuck with "web forms" then, but the data management of the objects are a lot more elegant. You could of course associate the object with a Web User Control or any other control collection as well. You could also just bypass the whole object serialization by returning XML directly from the SQL database and transforming it with XSLT. The possibilities are (almost) endless.

I tend to "complexify" a solution to make it scalable, easily adaptable and optimized, while still meeting the direct business needs of the application. Sort of, but not completely like building those "factory building factory factories"... :p
 
Last edited:
UPFRONT DISCLAIMER: Long post to follow. Made sense when I typed it, but I didn't re-read afterwards... :p

Well, how I usually design is as follows:
  • Database Layer
    An assembly dedicated to performing database calls. I usually have a base-class which manages the connection to the database itself, as well as any exception handling. This class also exposes methods to perform various calls to the database, i.e. "Update calls" (insert / update / delete) and "Getter calls" (returning datasets, tables, scalars or return values). For each business entity in the system, I then have a separate database class, inheriting from the base class. This derived class then interacts with the necessary tables via stored procedures - NEVER direct queries.
  • Business Layer
    An assembly dedicated to handling all business logic and representing all necessary business entities in object form. The business layer is the ONLY assembly that references the Database Layer. I create strongly-typed objects with the necessary member variables, properties and methods so as to correctly represent them in context of the business. I also make sure that the objects can be correctly serialized to XML (i.e. that the necessary properties will be correctly serialized to attributes, elements, enum or even ignored), so that web services utilizing this assembly will always return the correct serialized XML representation of the objects.
  • Interface / Presentation Layer
    Finally, the Interface Layer just handles the display and user interaction with the business entities. The Interface Layer only contains a reference to the Business Layer assembly. I prefer working with objects, as the properties are a lot more intuitive than trying to bind to column names in a data table. Also, calling the "Update" method for a specific object gives you much more control over what goes in the database, instead of just committing a dataset's contents to the database and hoping for the best. When working with a web application, I prefer to serialize the business objects to XML and transform it with the appropriate XSLT file. It makes for a nice, dynamic solution that you can easily adapt without having to rebuild and -deploy a complete solution.

Of course, then you can always follow the MVC / MVP route. In terms of ASP.NET MVC, its still (iirc) in a bit of a beta-phase, so I would personally wait a while and see how it pans out commercially (Stack Overflow is a nice example of a commercial ASP.NET MVC site though). I enjoy implementing a bit of a 3-tier / MVC hybrid solution though - I associate each business entity with a specific XSLT file, with a "RenderToHtml" method transforming the object's serialized XML with the specified XSLT file. You are still stuck with "web forms" then, but the data management of the objects are a lot more elegant. You could of course associate the object with a Web User Control or any other control collection as well. You could also just bypass the whole object serialization by returning XML directly from the SQL database and transforming it with XSLT. The possibilities are (almost) endless.

I tend to "complexify" a solution to make it scalable, easily adaptable and optimized, while still meeting the direct business needs of the application. Sort of, but not completely like building those "factory building factory factories"... :p

thanks good read :),

not always sure exactly how and when to use what type of solution or hybrid of solutions, but i guess kiss + scalabily and what works for what out of experiance should be the pointer.
 
There's the "new" Entity Framework for .NET, I've seen it in action it's awesome

You could build up an awesome DataLayer using the Entity Framework and then use Linq to Entities for all your CRUD queries :D

The cool thing about this framework is that the DB is abstracted, so if it's Oracal, SQL Server of MySQL all the same :) Using the Entity frame work, you can create an "OO"s style datalayer linked to the tables in the DB with all the goodies (e.g. Inheritance). Linq to Entities is type-safe and supports polymorphic statements in the queries.

There is even support for stored procedures in the framework so FarligOpptreden will be happy :p

I'm note sure if PLinq works to Entities yet but I'm sure if it doesn't it will in the future.
 
I assume this topic is specifically web-based applications because the n-Tier design in itself is a design pattern and Software Engineering Architecture for client-server based systems but in broad terms it's just based on the idea of separation of terms, high cohesion and loose coupling being the ideal.

There are quite a few of them here: http://en.wikipedia.org/wiki/Software_architecture
 
FarligOpptreden said:
...the term "Linq" just spoiled your whole post for me, sorry deq.

Necuno said:
not big fan of that either.

Why don't you guys like Linq? I'm still stuck in a VS 2005 .NET 2.0 world so I've never actually used it but from what I've read to me it sounds pretty cool :?
 
Why don't you guys like Linq? I'm still stuck in a VS 2005 .NET 2.0 world so I've never actually used it but from what I've read to me it sounds pretty cool :?

Still (predominantly) stuck with .NET 2.0 / VS2005, but I've played around with Linq and don't like it much. I don't like the idea of SQL-ifying your C# code (or is that C#-ifying your SQL code? :confused:)... I like to keep them apart, personally.
 
I'm with the OOP crowd with this one, on the decoupled side. The OP makes sense in that respect too - and no matter how I try, I end up with a tiered structure very similar to DB logic|business logic|display logic - it's all very frustrating. :p

ASP.Net MVC has reached V1.0, BTW. It also follows this tiered structure - strictly, in fact. One creates an object with the data (Model), which is returned to the Controller, which handles the logic and sends a completed set of data to the View. Strict separation exists - no calculations, etc. handled on the View, and the Model handles all database calls - the Controller acts as a mediary, and handles the business logic. Totally decoupled, totally awesome if done correctly. ;)
 
There's the "new" Entity Framework for .NET, I've seen it in action it's awesome

You could build up an awesome DataLayer using the Entity Framework and then use Linq to Entities for all your CRUD queries :D

The cool thing about this framework is that the DB is abstracted, so if it's Oracal, SQL Server of MySQL all the same :) Using the Entity frame work, you can create an "OO"s style datalayer linked to the tables in the DB with all the goodies (e.g. Inheritance). Linq to Entities is type-safe and supports polymorphic statements in the queries.

There is even support for stored procedures in the framework so FarligOpptreden will be happy :p

I'm note sure if PLinq works to Entities yet but I'm sure if it doesn't it will in the future.
Entity Framework is cool and you don't have to use Linq. It's your own choice! If you don't like it, and don't want to use it, you don't have to!
 
Entity Framework is cool and you don't have to use Linq. It's your own choice! If you don't like it, and don't want to use it, you don't have to!

Yes I've read about Entity SQL but I assume that would be the same and having inline paramatised SQL queries in your code?
 
The cool thing about this framework is that the DB is abstracted, so if it's Oracal, SQL Server of MySQL all the same :) Using the Entity frame work, you can create an "OO"s style datalayer linked to the tables in the DB with all the goodies (e.g. Inheritance). Linq to Entities is type-safe and supports polymorphic statements in the queries.

I've been using the entity framework and it is pretty awesome. It lets you retrieve data which otherwise would have been accessed with custom stored procs. Each table is represented by an object, its columns are object properties, and you can manipulate the object and have the changes reflect in the database (to put it very basically).

If you are using jsp, do you also have the front end / business layer / data layer split?
 
If you are using jsp, do you also have the front end / business layer / data layer split?
In my experience, yes. I used Struts though... on a badly designed application. I had to go through some 5-7 layers of interfaces to get to the actual code. Left a bad taste in my mouth.
 
If you are using jsp, do you also have the front end / business layer / data layer split?

This is a quick overview: http://java.sun.com/javaee/5/docs/tutorial/doc/bnaay.html

It can get fairly complicated tho, Java is aimed at Enterprise applications with redundancy, security and reliability as well as assured compatibility between components wheres .NET is more concerned with Rapid Application Development and components are restricted to MS (unless you want to run into possible stability issues).

There's a entire specification on how these applications are to be developed called Java Enterprise Edition, any components are designed around this specification, so long as the specs are followed you can run on multiple platforms (MS,Unix,Linux, Mac, etc.) with redundant servers, databases, load distribution, etc. if they all use JEE certified components.

I don't think MS has something like that yet, perhaps they will one day.
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X