concept business logic in category .net

appears as: business logic, The business logic, business logic
AOP in .NET

This is an excerpt from Manning's book AOP in .NET.

When you refactor to use AOP, you move all the red code (advice) into a new class, and all that should remain in the original class is the green code that performs the business logic. Then you tell the AOP tool to apply the aspect (red class) to the business class (green class) by specifying a pointcut. The AOP tool performs this combinational step with a process called weaving, as shown in figure 1.5.

In this chapter, we’ll mainly look at the business logic (the middle layer). We can assume that the persistence logic is already done (or that the decision of which persistence technology to use is being postponed and we’re instead using stubs or a transient in-memory database like SQLite for now). We’ll also assume that the UI will be implemented once the business logic is in place.

2.2.2. Testing the business logic

I created a simple Console UI project to simulate the use of the business logic, as the following shows.

Listing 2.2. A simple Console application to test the business logic

The business logic is now complete. Our code is clean and separated. It’s easy to read and it’s going to be easy to maintain. This service will get marketing pumped up, and it’s sure to increase your bonus once sales go through the roof.

NHibernate in Action

This is an excerpt from Manning's book NHibernate in Action.

Then, instead of directly working with the rows and columns of a DataTable, the business logic interacts with this object-oriented domain model and its runtime realization as a graph of interconnected objects. The business logic is never executed in the database (as a SQL stored procedure); it’s implemented in .NET. This allows business logic to use sophisticated object-oriented concepts such as inheritance and polymorphism. For example, you could use well-known design patterns such as Strategy, Mediator, and Composite [GOF 1995], all of which depend on polymorphic method calls.

The business logic in an entity expresses what the entity is supposed to do from a core domain point of view. Here is a simple implementation of the method Item.PlaceBid():

public void PlaceBid(Bid bid) {
if (bid == null)
throw new ArgumentNullException("bid");
if (bid.Amount < CurrentMaxBid.Amount )
throw new BusinessException("Bid too low.");
if (this.EndDate < DateTime.Now)
throw new BusinessException("Auction already ended.");
Bids.Add(bid);
CurrentMaxBid = bid;
}

This implementation illustrates the different kinds of business logic. You’ll see this method again in chapter 10, where we discuss more architectural decisions.

9.4. Implementing the business logic

In this book, we use the term business logic for any code that dictates how entities should behave. It defines what can be done with the entities and enforces business rules on the data they contain. Note that we aren’t strictly speaking about the domain model, but about the business layer in general.

The business layer can contain many kinds of business logic. We’ll use a case study to cover them all. Let’s say you want to implement a subsystem of the CaveatEmptor application that lets a user place a bid on an item; when this is done, all other bidders are notified of the new bid via email.