Business Layer in 3 tier Architecture
Asked Answered
M

5

16

I went for an interview, and was asked to show up my Business layer architecture. I have some idea about 3 tier architecture but really no idea, to what to write in front of interviewer. So suppose my project deals with Employees of an organization, then what would i have written there. Will it be any kind of diagrams i should have made or some coding part. I worked in C# framework 3.5. I really don't understand what else to mention in this question, so please let me know if something is required.Thanks.

Edit I worked in winforms. I know what Business layer is, but was not sure what to tell the interviewer as business layer has codes and obviously my project was a bit big, so there were huge numbers of codes. So what i should have written there??

Marry answered 22/9, 2011 at 6:21 Comment(4)
Was the question Show up your Business layer architecture only? Wasn't there some context? Did he explicitly asked you about a 3-tier architecture? If without context you were asked this question you should have answered that you have different architectures for different scenarios.Hallett
Isnt interview over or will you have a second round? :-)Circulate
@Darin:He asked me to show up 3 tier architectureMarry
@Davide:Unfortunately its over :-(Marry
N
24

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:

enter image description here

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.

Niggard answered 22/9, 2011 at 6:33 Comment(3)
There is a difference between layers and tiers. I think in the above, they have been used interchangeably.Morbidity
"...tiers are the physical deployment of layers."Niggard
Does business logic is frequently used in Controllers in MVC pattern? Talking about Web Development for example, every web page has a controller that "bounds" the entities in the models, so I can have helper classes and service layers both used in Controllers to be processed and displayed?Viviyan
A
1

Business logic is defined as any application logic that is concerned with the retrieval, processing, transformation, and management of application data; application of business rules and policies; and ensuring data consistency and validity. To maximize reuse opportunities, business logic components should not contain any behavior or application logic that is specific to a use case or user story. Business logic can be further subdivided into the following two categories:

  • Business Workflow. After the UI components collect the required data from the user and pass it to the business layer, the application can use this data to perform a business process. Many business processes involve multiple steps that must be performed in the correct order, and may interact with each other through an orchestration. Business workflow define and coordinate long running, multi step business processes, and can be implemented using business process management tools. They work with business process components that instantiate and perform operations on workflow components.
  • Business Entity Business Entity entities, or—more generally—business objects, encapsulate the business logic and data necessary to represent real world elements, such as Customers or Orders, within your application. They store data values and expose them through properties; contain and manage business data used by the application; and provide stateful programmatic access to the business data and related functionality. Business entities also validate the data contained within the entity and encapsulate business logic to ensure consistency and to implement business rules and behavior.
Aggappera answered 16/11, 2017 at 10:11 Comment(0)
T
0

3 Tier is as follows,

  1. Your presentation in one layer.
  2. Your application logic in other layer -- called business layer.
  3. Your Data Access classes in third layer. -- called Data Layer.

Webforms will be presentation layer So for employee class doing anything in ASP.Net code behind file can be considered business layer per my understanding as you are applying business rules using if/else and so forth. Data Access classes in App_Code folder would be Data Layer.

In case of desktop apps form designs would be presentation layer, form code will be business layer and anything related to accessing database would be data layer.

Tallbott answered 22/9, 2011 at 6:27 Comment(0)
F
0

Business layer layer that responsible for all business logic. For example you have Organizarion so organization and collection of employee. In employee object need to implement some restriction or some rules. This rules will be implemented in this layer.

Formula answered 22/9, 2011 at 6:29 Comment(1)
I down-voted, sorry. I don't think this answer gives enough information. Please expand it a bit. Maybe give some examples?Cristicristian
A
0

A 3-tier architecture is a type of software architecture which is composed of three “tiers” or “layers” of logical computing. They are often used in applications as a specific type of client-server system. 3-tier architectures provide many benefits for production and development environments by modularizing the user interface, business logic, and data storage layers.

Business Logic Layer: Business logic is the programming that manages communication between an end user interface and a database. The main components of business logic are business rules and workflows.

A Business Logic Layer (BLL) that serves as an intermediary for data exchange between the presentation layer and the DAL. In a real-world application, the BLL should be implemented as a separate Class Library project in App_Code folder in order to simplify the project structure. below illustrates the architectural relationships among the presentation layer, BLL, and DAL.

The BLL Separates the Presentation Layer from the Data Access Layer and Imposes Business Rules BLL

Aggappera answered 27/12, 2018 at 12:14 Comment(1)
The way you described Business Logic Layer sounds like it should understand the presentation layer in order to manage communication with it. Business Logic Layer should be indifferent of whatever the client application is ( web, desktop, mobile ) and simply define ways such applications could interact with it.Cristicristian

© 2022 - 2024 — McMap. All rights reserved.