The Artima Developer Community
Sponsored Link

Articles Forum
The DCI Architecture: A New Vision of Object-Oriented Programming

119 replies on 120 pages. Most recent reply: Jan 7, 2012 3:19 AM by Thorin Potjes

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 119 replies on 120 pages [ « | 1 ... 26 27 28 29 30 31 32 33 34 ... 120  | » ]
Christian Horsdal

Posts: 253
Nickname: horsdal
Registered: Mar, 2009

Re: The DCI Architecture: A New Vision of Object-Oriented Programming Posted: Mar 24, 2009 7:31 AM
Reply to this message Reply
Advertisement
> > You are way more infatuated with the abstract, academic
> > angle of this topic than concrete examples of how to
> build
> > working systems. To prove my point, your references
> are
> > all academic stuff, such as Alan Kay's and Doug
> > Englebart's visions of computing. There is nothing
> wrong
> > with linking to these things, but I am dumbfounded as
> to
> > why you aren't directly linking to the following:
> >
> > @DCI implementations also exist in C#/.Net (Christian
> > Horsdal Gammelgaard), Ruby (Steen Lenmann), Python
> (David
> > Byers and Serge Beaumont), and Groovy (Lars Vonk). The
> > Qi4J environment (Richard Öberg and Steen Lehmann) is
> > pushing forward the ability to express traits in a Java
> > environment.
> >
> > Why aren't you linking me directly to implementations so
> I
> > can play around with examples? One of Kay's big tenets
> is
> > learning should be constructive. Instead of letting me
> > play, you're linking me to more theory that I have to
> > digest before I can go play.
> >
> > No, no, no. Just no. Let me play with the code.
> >
> I'm not sure there's anyplace where that code has been
> made public. I'll ask. It is not secret or anything, but
> may not have been released publically. I'll post here if I
> find a link.
>
> Anyway, this is an idea article. We'll be publishing more
> articles exploring this area that will be more hands on.
> We'll do something on Qi4J, but I would point out that
> Qi4J isn't DCI. What they have in common is that DCI has a
> concept of roles that is implemented with this concept
> traits, and Qi4J provides a way to do that trait-like
> concept in Java.

As for the C# implementation mentioned I have only made a small proof-of-concept example, but I am working on a larger example, which will give a better impression of how nicely (or not) my implementation would work in a real application.
The C# approach is to use C# interfaces for methodless roles, use C# interfaces and extension methods for methodful roles, and just use POCOs for context and domain object. To be concrete the following is a really short example:
namespace AccountSample
{
	// Methodless roles
	public interface TransferMoneySink
	{
	}
 
 
	// Methodfull roles
	public interface TransferMoneySource
	{
	}
 
	public static class TransferMoneySourceTraits
	{
		public static void TransferFrom(this TransferMoneySource self, TransferMoneySink recipient, double amount)
		{
			Account self_ = self as Account;
			Account recipient_ = recipient as Account;
 
			// Selfcontained readable and testable algorithm
 
			if (self_ != null && recipient_ != null)
			{
				self_.Withdraw(amount);
				self_.Log("Withdrawing " + amount);
				recipient_.Deposit(amount);
				recipient_.Log("Depositing " + amount);
			}
		}
	}
 
 
	// Context object
	public class TransferMoneyContext
	{
		// Properties for accesing 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, Amount);
			// Alternatively the context could be passed to the source and sink object.
		}
	}
 
 
	// Abstract domain object
	public abstract class Account
	{
		public abstract void Withdraw(double amount);
		public abstract void Deposit(double amount);
		public abstract void Log(string message);
	}
 
	// Concrete domain object
	public class SavingsAccount : Account, TransferMoneySource, TransferMoneySink
	{
		private double balance;
 
		public SavingsAccount()
		{
			balance = 10000;
		}
 
		public override void Withdraw(double amount)
		{
			balance -= amount;
		}
 
		public override void Deposit(double amount)
		{
			balance += amount;
		}
 
		public override void Log(string message)
		{
			Console.WriteLine(message);
		}
 
		public override string ToString()
		{
			return "Balance " + balance;
 
		}
	}
 
 
 
	// Test app
	public class Program
	{
		public static void Main(string[] args)
		{
			SavingsAccount src = new SavingsAccount();
			SavingsAccount snk = new SavingsAccount();
 
			Console.WriteLine("Before:");
			Console.WriteLine("Src:" + src);
			Console.WriteLine("Snk:" + snk);
 
			Console.WriteLine("Run transfer:");
			new TransferMoneyContext(src, snk, 1000).Doit();
 
			Console.WriteLine("After:");
			Console.WriteLine("Src:" + src);
			Console.WriteLine("Snk:" + snk);
 
			Console.ReadLine();
		}
	}
 
}

Flat View: This topic has 119 replies on 120 pages [ « | 26  27  28  29  30  31  32  33  34 | » ]
Topic: Effect Choreography in Flex 4 Previous Topic   Next Topic Topic: Cooperative Visitor: A Template Technique for Visitor Creation

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use