Composition in OpenEdge classes

Posted by Johan Vergeer on 20-Mar-2017 08:50

I have a question regarding the use of composition in OpenEdge classes. 

I come from a C# / Java background and it looks like OpenEdge takes a different approach here. 

We have a use case where an order should be added to the database. 

In C# (using Entity Framework) I would create some entities like Order, OrderLine and Customer

The way the entity classes would be build is like this:

class Order {

    public int OrderId {get; set; }

    public int CustomerId {get; set; }

    public virtual Customer Customer { get; set; }

    public virtual ICollection<OrderLine> OrderLines {get; set; }

}

class Customer {

    public int CustomerId {get; set; }

    public virtual ICollection<Order> Orders { get; set; }

}

class OrderLine {

    public int OrderLineId {get; set; }

    public int OrderId { get; set; }

    public virtual Order Order {get; set; }

}

I have done several OpenEdge courses but am still trying to get all the pieces into the right place here.

Like in the IntroToOOP course I can see that I would have to use an order temp-table with a CustomerObj field. And the Customer object would hold a temp-table containing all the customer info. But then what would I do with all the properties for Customer.

When a property updates, that that would have to be changed in the Customer object and in the Customer temp-table.

What I would like to do is just use a  AddOrder() method in the Customer class to create a new order, and then do something like customer:order:AddOrderLine().

What would be the best way to accomplish this in OpenEdge?

Posted by Peter Judge on 20-Mar-2017 09:30

There’s no built-in ORM in ABL, and opinions are divided as to their benefit in ABL.
 
You can create a temp-table with any structure you want … it can match the db schema exactly or you can make it more readable/more normalized, add calculated (derived) fields.
 
There’s nothing standing in your way of doing what you want  - like C#, ABL has properties which you can use to chain stuff, or you can use the method approach java requires. You should be able to encapsulate the temp-table/data access in classes quite easily. I’ve seen approaches which use the active record pattern and others that do a bunch of dynamic stuff . There’s no one right way.
 

All Replies

Posted by Peter Judge on 20-Mar-2017 09:30

There’s no built-in ORM in ABL, and opinions are divided as to their benefit in ABL.
 
You can create a temp-table with any structure you want … it can match the db schema exactly or you can make it more readable/more normalized, add calculated (derived) fields.
 
There’s nothing standing in your way of doing what you want  - like C#, ABL has properties which you can use to chain stuff, or you can use the method approach java requires. You should be able to encapsulate the temp-table/data access in classes quite easily. I’ve seen approaches which use the active record pattern and others that do a bunch of dynamic stuff . There’s no one right way.
 

Posted by Johan Vergeer on 21-Mar-2017 01:42

Hi Peter, so it is like any other language. :)

Although it would be easier sometimes to have "One Ring to rule them all".

This thread is closed