Mega Code Archive

 
Categories / Delphi / Examples
 

Whats the ECO framework

Title: What's the ECO framework? Question: ECO and Bold share the same idea to provide executable UML, in bref what lies behind ECO for Delphi.net ? Answer: ECO is a cutting edge technology from Borland ;) The Version Delphi 8 for .NET contains support for ECO - the Enterprise Core Objects. ECO is only available in the architect edition or the personal /trial edition. Delphi 2005 does a glance with the ECO2 framework. ECO is only available for Delphi.net or C# projects, but not for Win32 targets. But since April 2005 also Bold is available for D2005 (compiled packages) and win32 targests! Documentation for Bold for Delphi2005 is available on http://info.borland.com/techpubs/delphi/boldfordelphi/. Maybe you know Bold. Borland made in 2003 the aquisition of boldsoft sweden and the bold-team too, so the essence and different layers of Bold you may also find in ECO. But Bold is dependent on special BoldControls where ECO is independent. Why: ECO needs to have the model compiled so the GUI designer can display the model information. The runtime system of ECO relies on the interrogation of the classes using .Net Reflection. For Reflection to work you must compile the application! Bold for Delphi 6 or 7 and ECO for Delphi 8/2005 applies Object Oriented flexibility and design to a persistence layer of the application making design, maintainability and reuse easier. It is worth spending time on this upfront because this is a huge part of the productivity enhancement you will experience when using Bold /ECO for Delphi architecture. UML is critical for the use of ECO. The Delphi product line includes its own UML modeling tool, either ModelMaker or Together. Learning UML is more or less easy and applying the full range of UML modeling techniques (especially class- and sequence diagram) is a rewarding process. How it works? ------------------------------------------------ ECO forces developers to work model centric (MDA) where most of the nowadays object relational mapping frameworks lean against data centric development. The question is if it is at its best by first designing your data model in conjunction with your use case scenarios and then map against classes or first design the class model and the map against a persistent data model or an XML file set. ECO works the second way. Nary a company whishes the "rip-and-replace" mantra because it is costly, instead opting to rework, rebuild code and build it out to scale for necessary IT projects. ECO like Bold is a persistence engine layer with code generator using a model-driven architecture in class models and provides a run-time OCL (Object Constraint Language) evaluator/query language and a complete run-time UML meta-model from the help of the ECO Space. So instead of SQL you deal with OCL using not only databases as store your data, also XML files, binaries or other persistence. What's the ECO Space? ------------------------------------------------ Fromm the Borland Delphi help file: "An ECO Space is a container of objects. At runtime, the ECO Space contains actual instances of the classes in your model. It is helpful to think of the ECO Space as an actual instance of a model, much like an object is an instance of a class. The objects contained in the ECO Space retain the domain properties (attributes and operations) and relationships defined in the model. As a container of objects, an ECO Space is both a cache, and a transactional context. Within the ECO Space, another component called a persistence mapper is used as the conduit between the persistence layer (either an RDBMS or XML file), and the instances of the classes defined in the model. When you configure an ECO Space using the IDE, you will select those UML packages in your model that you wish to persist in the ECO Space." A caveat: In reality this transformation results in an implementation that loses or can lose the intent of the original class model and may even drop off important business rules if careful documentation processes arent followed, cause the direction is only forward (no fumble around in generated code). Indeed even if these rules are documented it is reliant on them being understood and implemented by the application programmer. As with all documentation it must also be manually maintained during the life cycle of the database. What's OCL? ------------------------------------------------ OCL is a formal language for adding information to UML models. That information can be divided broadly into two categories: - constraints and queries. The query side of OCL is often a surprise to developers learning OCL. In fact OCL can express any query that can be expressed in standard SQL. Given that flexibility, OCL can provide a variety of additions to UML class diagrams and other diagrams in a model. OCL can be used to describe valid values for properties, pre and post conditions for operations, calculated property values and object queries and the important thing is, OCL doesn't changes the data. Maybe you've heard the Design by Contract principle which also OCL and his constraints or condition stands for. OCL like Pascal is a strongly typed language. ECO in Delphi and Eclipse Modeling Framework (EMF, Java) mappings are provided as examples of mapping OCL to a purpose-built model implementation frameworks. Starting with ECO ------------------------------------------------- 1. There is a great starter from Bob, how we can use the Architect edition Delphi 8 for .NET, and specifically the functionality found in ECO to design an Object Model (EcoSpace) which is made persistent inside a database, such as SQL Server or InterBase in this case at http://www.ebob42.com/sdc/2004/ECO.htm A top second starter in german language with ECO II/ D2005 is at: http://www.softwareschule.ch/download/eco2.pdf 2. Delphi.NET provides in Demos/ECO two examples to built, in D2005 five Examples: Before running an example, take a look at the UML class diagram by selecting View | Model View in the IDE. Then expand the CoreClasses node, representing a UML Package, to expose the included classes and associations (if any). Double-click the diagram node (also named CoreClasses) within the package, to open the diagram designer. Both examples uses an XML file for persistence. http://www.borland.com/delphi_net/architect/eco/tutorial/ Those are the steps: 1. Start Delphi 2005, and select File | New - Other which will show the Delphi 2005 Object Repository. 2. Define the model. For this, we need to click on the Model View tab of the Project Manager. We open the treeview with the model nodes, and select the CoreClasses node. Expand this node, and select the CoreClasses leaf node inside. This is the node that we can use to draw the UML diagram (classes, packages) for our ECO model. 3. Build the form with expression handles. This is the ReferenceHandle between the Form and the EcoSpace (and all objects inside it) the connection between the delphi.net form and the ECO objects and lists. 4. Set the persistence mapper component. A handle can be used to evaluate an OCL expression, returning all instances of an ECO class which came from a XML file for example: Self.PersistenceMapperELocoXml1.FileName:= '\locomotivestore2.xml'; 5. Store the data just smart and easy: procedure TWinForm.btnstore_Click(sender: System.Object; e: System.EventArgs); begin ecoSpace.UpdateDatabase end; Abstract: ------------------------------------------------- ECO is a purpose-built model implementation framework which is based on 4 different toolsets: - UML (use case, class- sequence- package diagram etc.) - OCL to set the business rules and "protecting" your code - Persistence Mapping (object relational) to bridge the gap between classes and relational databases [EcoSpacePackage(TypeOf(CoreClassesUnit.CoreClasses))] - OOP to deal with lists and interfaces and separate the GUI from the logic- and data layer Short view of ECO generated Code CoreClassesUnit.pas This file contains an empty "UML package". This is where the classes for our ECO application will be created by default. It is possible to create multiple packages. ------------------------------------------------- unit CoreClassesUnit; interface uses System.ComponentModel, System.Collections, Borland.Eco.Services, Borland.Eco.ObjectRepresentation, Borland.Eco.ObjectImplementation, Borland.Eco.UmlRt, Borland.Eco.UmlCodeAttributes; type Person = class; Building = class; ResidentialBuilding = class; IBuildingList = interface; [UmlElement('Package')] [UmlMetaAttribute('ownedElement', TypeOf(Person))] [UmlMetaAttribute('ownedElement', TypeOf(Building))] [UmlMetaAttribute('ownedElement', TypeOf(ResidentialBuilding))] CoreClasses = class public type [UmlElement('Association')] Ownership = class end; type [UmlElement('Association')] Residents = class end; end; -------------------------------------------------- procedure TBldOwnEcoSpace.InitializeComponent; begin Self.PersistenceMapperXml := Borland.Eco.Persistence.PersistenceMapperXml.Create; // // PersistenceMapperXml // Self.PersistenceMapperXml.CacheData := False; Self.PersistenceMapperXml.FileName := 'EcoBuilding.Data'; // // TBldOwnEcoSpace // Self.PersistenceMapper := Self.PersistenceMapperXml; end; ...see you at EKON9 in Frankfurt ;)