Skip to Content
Lean Architecture for Agile Software Development
book

Lean Architecture for Agile Software Development

by James Coplien, Gertrud Bjørnvig
August 2010
Intermediate to advanced
376 pages
10h 6m
English
Wiley
Content preview from Lean Architecture for Agile Software Development

Appendix C. Account Example in C#

Christian Horsdal Gammelgaard provides the following code in C#, using the extension method facility as a way to demonstrate injection of role functionality into a domain class.

using System;

namespace DCI
{
    // Methodless role types
    public interface TransferMoneySink
    {
    }

    // Methodful roles
    public interface TransferMoneySource
    {
    }

    public static class TransferMoneySourceTraits
    {

        public static void TransferFrom(
                this TransferMoneySource self,
                TransferMoneySink recipient, double amount)
        {
            // This methodful role can only
            // be mixed into Account object (and subtypes)
Account self_=self as Account;
            Account recipient_=recipient as Account;

            // Self-contained readable and testable
            // algorithm

            if (self_ != null && recipient_ != null)
            {
                self_.DecreaseBalance(amount);
                self_.Log("Withdrawing " + amount);
                recipient_.IncreaseBalance(amount);
                recipient_.Log("Depositing " + amount);
            }
         }
      }


     // Context object
     public class TransferMoneyContext
     {
         // Properties for accessing the concrete objects
         // relevant in this context through their
         // methodless roles
         public TransferMoneySource Source {
             get; private set;
         }

         public TransferMoneySink Sink {
             get;
             private set;
         }

         public double Amount {
             get; private set;
         }

         public TransferMoneyContext()
         {
             // logic for retrieving source and sink accounts
         }

         public TransferMoneyContext(
                         TransferMoneySource source,
TransferMoneySink sink, double amount) { Source = source; Sink = sink; Amount = amount; } public void Doit() { Source.TransferFrom(Sink, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Agile Software Architecture

Agile Software Architecture

Muhammad Ali Babar, Alan W. Brown, Ivan Mistrik
Lean Software Development: An Agile Toolkit

Lean Software Development: An Agile Toolkit

Mary Poppendieck, Tom Poppendieck

Publisher Resources

ISBN: 9780470684207Purchase book