5. Business Code
public class CustomerProcesses
{
public void RentBook( int bookId, int customerId )
{
Book book = Book.GetById( bookId );
Customer customer = Customer.GetById( customerId );
book.RentedTo = customer;
customer.AccountLines.Add(
string.Format( "Rental of book {0}.", book ), book.RentalPrice
);
customer.Balance -= book.RentalPrice;
}
}
8. Business Code
public class CustomerProcesses
{
public void RentBook( int bookId, int customerId )
{
Book book = Book.GetById( bookId );
Customer customer = Customer.GetById( customerId );
book.RentedTo = customer;
customer.AccountLines.Add(
string.Format( "Rental of book {0}.", book ), book.RentalPrice
);
customer.Balance -= book.RentalPrice;
}
}
9. Business Code
+ Logging
internal class CustomerProcesses
{
private static readonly TraceSource trace =
new TraceSource( typeof (CustomerProcesses).FullName );
public void RentBook( int bookId, int customerId )
{
trace.TraceInformation(
"Entering CustomerProcesses.CreateCustomer( bookId = {0},
customerId = {1} )",
bookId, customerId );
try
{
Book book = Book.GetById( bookId );
Customer customer = Customer.GetById( customerId );
book.RentedTo = customer;
customer.AccountLines.Add(
string.Format( "Rental of book {0}.", book ), book.RentalPrice );
customer.Balance -= book.RentalPrice;
trace.TraceInformation(
"Leaving CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )",
bookId, customerId );
}
catch ( Exception e )
{
trace.TraceEvent( TraceEventType.Error, 0,
"Exception: CustomerProcesses.CreateCustomer(
bookId = {0}, customerId = {1} ) failed : {2}",
bookId, customerId, e.Message );
throw;
}
}
}
10. Business Code
+ Logging
internal class CustomerProcesses
+ Vorbedingungen {
private static readonly TraceSource trace =
new TraceSource(typeof(CustomerProcesses).FullName);
public void RentBook(int bookId, int customerId)
{
if (bookId <= 0) throw new ArgumentOutOfRangeException("bookId");
if (customerId <= 0) throw new ArgumentOutOfRangeException("customerId");
trace.TraceInformation(
"Entering CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )",
bookId, customerId);
try
{
Book book = Book.GetById(bookId);
Customer customer = Customer.GetById(customerId);
book.RentedTo = customer;
customer.AccountLines.Add(string.Format("Rental of book {0}.", book),
book.RentalPrice);
customer.Balance -= book.RentalPrice;
trace.TraceInformation(
"Leaving CustomerProcesses.CreateCustomer( bookId = {0},
customerId = {1} )“, bookId, customerId);
}
catch (Exception e)
{
trace.TraceEvent(TraceEventType.Error, 0,
"Exception: CustomerProcesses.CreateCustomer( bookId = {0},
customerId = {1} ) failed : {2}",
bookId, customerId, e.Message);
throw;
}
}
}
11. Business Code
+ Logging + Transaktionen
+ Vorbedingungen
internal class CustomerProcesses ts.Complete();
{ }
private static readonly TraceSource trace =
new TraceSource(typeof(CustomerProcesses).FullName); break;
}
public void RentBook(int bookId, int customerId) catch (TransactionConflictException)
{ {
if (bookId <= 0) if (i < 3)
throw new ArgumentOutOfRangeException("bookId"); continue;
if (customerId <= 0) else
throw new ArgumentOutOfRangeException("customerId"); throw;
}
trace.TraceInformation( }
"Entering CustomerProcesses.CreateCustomer( bookId = {0},
customerId = {1} )“, bookId, customerId); trace.TraceInformation(
"Leaving CustomerProcesses.CreateCustomer(
try bookId = {0}, customerId = {1} )",
{ bookId, customerId);
for (int i = 0; ; i++) }
{ catch (Exception e)
try {
{ trace.TraceEvent(TraceEventType.Error, 0,
using (var ts = new TransactionScope()) "Exception: CustomerProcesses.CreateCustomer( bookId = {0},
{ customerId = {1} ) failed : {2}",
Book book = Book.GetById(bookId); bookId, customerId, e.Message);
Customer customer = throw;
Customer.GetById(customerId); }
}
book.RentedTo = customer;
customer.AccountLines.Add( }
string.Format("Rental of book {0}.", book),
book.RentalPrice);
customer.Balance -= book.RentalPrice;
12. Business Code
+ Logging + Transaktionen
+ Vorbedingungen + Exception Handling
internal class CustomerProcesses
{ ts.Complete();
private static readonly TraceSource trace = }
new TraceSource(typeof(CustomerProcesses).FullName);
break;
public void RentBook(int bookId, int customerId) }
{ catch ( TransactionConflictException )
if (bookId <= 0) throw new ArgumentOutOfRangeException("bookId"); {
if (customerId <= 0) if ( i < 3 )
throw new ArgumentOutOfRangeException("customerId"); continue;
else
try throw;
{ }
trace.TraceInformation( }
"Entering CustomerProcesses.CreateCustomer(
bookId = {0}, customerId = {1} )", trace.TraceInformation(
bookId, customerId ); "Leaving CustomerProcesses.CreateCustomer(
bookId = {0}, customerId = {1} )",
try bookId, customerId );
{ }
for ( int i = 0;; i++ ) catch ( Exception e )
{ {
try trace.TraceEvent( TraceEventType.Error, 0,
{ "Exception: CustomerProcesses.CreateCustomer(
using ( var ts = new TransactionScope() ) bookId = {0}, customerId = {1} ) failed : {2}",
{ bookId, customerId, e.Message );
Book book = Book.GetById( bookId ); throw;
Customer customer = Customer.GetById( customerId ); }
}
book.RentedTo = customer; catch ( Exception e )
customer.AccountLines.Add( {
string.Format( "Rental of book {0}.", book ), if (ExceptionManager.Handle(e)) throw;
book.RentalPrice ); }
customer.Balance -= book.RentalPrice; }
13. Business Code
+ Logging + Transaktionen
+ Vorbedingungen + Exception Handling
+ Feature X
+ Feature Y
+ Feature Z
+…
14. Kern- Seperation
funktionalitäten of Concerns
(Core Concerns)
20. Build-Time: “Statisch” Run-Time: “Dynamisch”
Erfolgt bei Kompilierung Erfolgt zur Laufzeit
Code wird direkt verändert Code bleibt unverändert
Zur Laufzeit keine Änderungen Zur Laufzeit Änderungen möglich
Auch auf Properties, Felder, Aufruf wird über Proxy
Events anwendbar umgeleitet
Keine Interfaces erforderlich idR. Interfaces erforderlich (Proxy)