DSL, , , , , .
DSL , . , DSL ( " " AKA) DSL, . , , .
; tl; dr.
. - API, , :
public abstract class Message
{
public byte[] GetBytes()
{
using (MemoryStream ms = new MemoryStream())
{
byte[] result = new byte[ms.Length + 3];
result[0] = 0xFF;
result[1] = (byte)ms.Length;
WriteMessageData(result, 2);
result[result.Length - 1] = GetChecksum(result, 0,
result.Length - 2);
return result;
}
}
protected abstract void WriteMessageData(byte[] buffer, int offset);
}
(). , , , 30 , , , . :
public class AddMessage : Message
{
private const byte id = 0x9F;
protected override void WriteMessageData(byte[] buffer, int offset)
{
buffer[offset] = id;
MessageUtil.WriteInt32(buffer, offset + 1, Num1);
MessageUtil.WriteInt32(buffer, offset + 5, Num2);
}
public int Num1 { get; set; }
public int Num2 { get; set; }
}
, . , . , . . , . , 30 .
. , :
public int Add(int num1, int num2)
{
AddMessage msg = new AddMessage();
msg.Num1 = num1;
msg.Num2 = num2;
MessagingSystem.SendMessage(msg);
AddResultMessage result = MessageSystem.Receive<AddResultMessage>();
if (result == null)
{
throw new InvalidResultException("AddResultMessage");
}
return result.Sum;
}
--, . . API, . , 10, 20, 50, 100, 1000..., .
, " " -?
Message(Add)
Send: Num1 int, Num2 int
Receive: Sum int
Message(Multiply)
Send: Num1 int, Num2 int
Receive: Product int
Message(Divide)
Send: Divisor int, Dividend int
Receive: Quotient int, Remainder int
, , kludgy-, . , , , -, , , . :
MyMessagingSystem ms = new MyMessagingSystem();
int sum = ms.Add(3, 4).Sum;
int product = ms.Multiply(5, 6).Product;
DivideResult = ms.Divide(10, 5);
, , DSL ( , ), 20 , OO 3 DSL-.
. . , DSL , , , , , .
( ) "" DSL? . : , , , .
DSL . , , , , /. , . , . , .
, " " DSL; , . , " " . DSL ( , IMO) :
Event: PaymentReceived(Payment)
Validation:
Condition: Amount > 0, "Invalid payment amount"
Condition: Date > Today - 7d, "Cannot backdate > 7 days"
Actions:
Update: Account(AccountID)
SetProperty: Account.Balance, Account.Balance - Payment.Amount
SetProperty: Account.LastPaymentDate, Payment.Date
Notify: Billing
Template: PaymentReceived.xlt
Field: CustName, CustomerName
Field: PaymentAmount, Amount
Field: PaymentDate, Date
.., . . , , !
? ? - , ; , . , , ? ? - , , , Validation . - DSL, :
Event: PaymentReceived(Payment)
Validation:
Condition: All(
PaymentType = Cheque,
Account(Payment.AccountID).DelinquentFlag = False
), "Cheques no longer allowed for this customer"
, , , , "-...". : ", , , ".
, DSL, , :
Notify: Management
Condition: All(
PaymentType = Cheque,
Account(Payment.AccountID).DelinquentFlag = False
)
Template: DelinquentCheque.xlt
Field: CustName, CustomerName,
...
? "" . , . , , DSL .
. ?
, DSL . , , , . , , "" , , , - .
, DSL, -, , , , , . . , . , , DSL, , , , , , .
, " ", , API. . , , DSL, . , . " -", , , Turbo Pascal 1.0.
tl; dr :
, , , "WTF?"? , :
. , -, "", "" .
, . DSL API, DSL , , , . , , , .
. DSL , . - ; / . , , .
. , , , , - , , DSL .
, . , !