Saturday, June 12, 2010

A faq about using Bold for Delphi

A FAQ about Bold for Delphi
  1. What is the requirements to start using Bold ?
  2. What is UML ?
  3. What is ORM ?
  4. What is OCL ?
  5. What is a derived member ?
Q: What is the requirements to start using Bold ?
A: Currently Bold is only available in 3 editions, all in obsolete versions of Delphi:
  • Delphi 7 Architect.
  • Delphi 2005 Architect
  • Delphi 2006 Architect
  • Delphi 2007 using package from Delphi 2006
So Bold can be used with D2007 if the package was compiled with D2006 as they are binary compatible.

Q: What is UML ?
A: UML (Unified Modeling Language) is a standardized general-purpose modeling language. Bold use MDA (Model-driven architecture) meaning that a change of the model is the first step in development. Then that change is applied on the database. Then the code may be changed to adapt to the previous model changes. In UML you can specify relations between classes as singlelinks (on to one) or multilinks (one to many). Each class can have attributes of basic datatypes and methods attached.
See also UML on Wikipedia

Q: What is ORM ?
A: ORM (Object-relational mapping) means to convert relations in a traditional SQL database to objects in memory that can be used with a objectoriented language. It is of course possible to change objects and store them in the database. This makes programming much easier as it is not needed to write SQL to read and writa data from the database. It is much easier to write complex expressions if you don't need to use SQL.

Compare this by OCL ?:

PlanMission.allinstances->select(created > #2010-02-04).created

and in SQL:

SELECT created FROM PlanMission WHERE (PlanMission.Created > '2010.02.04')

See also ORM on Wikipedia.

Q: What is OCL ?
A: OCL (Object Constraint Language) is a language that is used a lot in Bold. It has no sideeffects meaning that there is no way of changing objects. All operations is read-only. It is easy to work with a list of objects and filter a certain property or type.

You can build an OCL expression in designtime by a dialog that contains a context sensitive list of keywords.












See also OCL on Wikipedia.

Q: What is a derived member ?
A: A derived member is typically not stored in the database. It is transistant and exists only in Bolds objectspace in RAM. For example if you have 3 classes Invoice, InvoiceRow and Vat.
The InvoiceRow have the attribute NetValue and a singlelink to Invoice. Invoice have a single link to Vat and a multilink InvoiceRows. Vat have an attribute VatValue.
Now InvoiceRow can have 2 derived attributes VatValue and TotalValue. Invoice can also have 3 derived attributes NetValue, VatValue and TotalValue. See the model.
UML model
So class Invoice have 3 attributes, InvoiceRow also 3 and Vat have 1. Only 2 of those 7 attributes are stored persistent in the database, The remaining 5 is marked as derived with a / before the name.

We can define the value for a derived attribute in a method or in OCL. Often OCL is simpler and safer. In code you have to take care of subscribing other attributes and objects in case they change. In OCL this occurs automatic.

OCL expressions for derived attributes:

  • InvoiceRow.vatValue: netvalue * mainInvoice.invoiceVat.vatValue
  • InvoiceRow.totalValue: netValue + vatValue
  • Invoice.netValue: invoiceRows.netValue->Sum
  • Invoice.vatValue: netValue * invoiceVat.vatValue
  • Invoice.totalValue: invoiceRows.totalValue->Sum
Derived attributes have the property that they are recalculated every time a dependent object change and that attribute is read.

NOTE: The recalc does only happen if the derived attribute is read.

In this case if one of the Invoicerows netValue change and this InvoiceRows vatValue is read it notice the change and recalc. But totalValue is not recalced until it is read. When Invoice.totalValue is read it will be recalced if any of the other attrbutes have changed value. If nothing has changed the attribute value is cached and the calculation will not happened.

This behaviour save CPU time specially for complex expressions. Compare if those attributes would be methods that do the calculations every time they where called. And of course the chain of derivations can be arbitrary long and complex.