a 3 tier Architecture is composed by 3 Main Layers
- PL Presentation Layer
- BLL Business Logic Layer
- DAL Data Access Layer
each top layer only asks the below layer and never sees anything on top of it.
When They ask you about How will you build your BLL, you can write something like:
namespace Company.BLL
{
// let's create an interface so it's easy to create other BLL's if needed
public interface ICompanyBLL
{
public int Save(Order order, UserPermissions user);
}
public class Orders : ICompanyBLL
{
// Dependency Injection so you can use any kind of BLL
// based in a workflow for example
private Company.DAL db;
public Orders(Company.DAL dalObject)
{
this.db = dalObject;
}
// As this is a Business Layer, here is where you check for user rights
// to perform actions before you access the DAL
public int Save(Order order, UserPermissions user)
{
if(user.HasPermissionSaveOrders)
return db.Orders.Save(order);
else
return -1;
}
}
}
As a live example of a project I'm creating:
PL's are all public exposed services, my DAL handles all access to the Database, I have a Service Layer that handles 2 versions of the service, an old ASMX and the new WCF service, they are exposes through an Interface
so it's easy for me to choose on-the-fly what service the user will be using
public class MainController : Controller
{
public IServiceRepository service;
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
...
if (thisUser.currentConnection.ws_version == 6)
// Use old ASMX Web Service
service = new WebServiceRepository6(url, ws_usr, ws_pwd);
else if (thisUser.currentConnection.ws_version == 7)
// Use the brand new WCF Service
service = new WebServiceRepository7(url, ws_usr, ws_pwd);
...
}
}
In the code above, I simply use Dependency Injection to separate the knowladge of the other layer, as at this layer (the Presentation Layer as this is a Controller in a MVC project) it should never care about how to call the Service and that the user uses ServiceA
instead of ServiceB
... What it needs to know is that calling a IService.ListAllProjects()
will give the correct results.
You start dividing proposes and if a problem appears in the service connection, you know that's nothing to do with the Presentation Layer, it's the service Layer (in my case) and it's easy fixed and can be easily deployed a new service.dll
instead publishing the entire website again...
I also have a helper that holds all Business Objects that I use across all projects.
I hope it helps.
If you are expecting to be able to "flatten" List(1, 2, List(3,4), 5)
into List(1, 2, 3, 4, 5)
, then you need something like:
implicit def any2iterable[A](a: A) : Iterable[A] = Some(a)
Along with:
val list: List[Iterable[Int]] = List(1, 2, List(3,4), 5) // providing type of list
// causes implicit
// conversion to be invoked
println(list.flatten( itr => itr )) // List(1, 2, 3, 4, 5)
EDIT: the following was in my original answer until the OP clarified his question in a comment on Mitch's answer
What are you expecting to happen when you flatten
a List[Int]
? Are you expecting the function to sum the Int
s in the List
? If so, you should be looking at the new aggegation functions in 2.8.x:
val list = List(1, 2, 3)
println( list.sum ) //6
Best Answer
This is what I have in my project.
1.) Application.Infrastructure
2.) Application.DataModel
3.) Application.DataAccess
4.) Application.DomainObjects
5.) Application.BusinessLayer
6.) Application.WebClient or Application.WindowsClient
Application.BusinessObjects are used across the application and they travel across all layers whenever neeeded [except Application.DataModel and Application.Infrastructure]
All my queries are defined only Application.DataModel.
Application.DataAccess returns or takes Business objects as part of any data-access operation. Business objects are created with the help of reflection attributes. Each business object is marked with an attribute mapping to target table in database and properties within the business object are marked with attributes mapping to target coloumn in respective data-base table.
My validation framework lets me validate each field with the help of designated ValidationAttribute.
My framrwork heavily uses Attributes to automate most of the tedious tasks like mapping and validation. I can also new feature as new aspect in the framework.
A sample business object would look like this in my application.
User.cs
BookCollection.cs