> > 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
publicinterface TransferMoneySink
{
}
// Methodfull roles
publicinterface TransferMoneySource
{
}
publicstaticclass TransferMoneySourceTraits
{
publicstaticvoid 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
publicclass 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; }
publicdouble 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;
}
publicvoid Doit()
{
Source.TransferFrom(Sink, Amount);
// Alternatively the context could be passed to the source and sink object.
}
}
// Abstract domain object
publicabstractclass Account
{
publicabstractvoid Withdraw(double amount);
publicabstractvoid Deposit(double amount);
publicabstractvoid Log(string message);
}
// Concrete domain object
publicclass SavingsAccount : Account, TransferMoneySource, TransferMoneySink
{
privatedouble 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
publicclass Program
{
publicstaticvoid 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
[
«
|
262728293031323334
|
»
]