Board index » delphi » Aggregate or Object Master-Detail question

Aggregate or Object Master-Detail question

Hi all !

I'm wondering if someone could help me with advice on design of classes in Delphi 6 ?

Case:
I'm working on a Transportation EDI (Electronic Data Interchange) app. Currently we have the
Norwwegian Postal Service in this app, but we're going to add several others soon. This makes me
realize that my app is too database oriented and it's not flexible enough.

Problem:
In our client version, several "senders" can send packages to several "receivers" each. I have to
make a lot of checks on the different values for each sender and receiver before I allow the EDIFact
message to be generated. This is why I want to create an object for each sender and an object for
each receiver.

What I'm after:
I would like to do something like this:
1) Create a list of objects holding each sender.
2) Create a list of receivers belonging to this sender

How do I refer to the receiver that belongs to the sender. I mean: If I move to the next sender, I
should only see the receivers which belongs to that sender.

Hope that I've explained properly, and that someone is willing to use his valueable time to come
with a suggestion.

Thanks in advance.

I'm using D6 Pro - update 2 under Windows 2000
****************************************************
Best wishes
Kai Bohli
kaiboeNOS...@online.no
Norway
****************************************************

 

Re:Aggregate or Object Master-Detail question


Quote
> How do I refer to the receiver that belongs to the sender.

Presumably, the list of receivers is not unique for each sender (eg the
postal service could be a receiver for 2 or more senders)?

In this case, I would not have the receivers "belong" to senders. I
would have the senders keep a list of references to receivers. The
normal way to do this is to create all the senders and receivers
separately, and have say, the receivers register with the appropriate
senders when it is added (and removed, usually). This is sort of like
the way many data aware controls register themselves with a TDataSource.
You can make it two-way (ie get the list of receivers for a sender, and
the senders for a receiver).

If you can find a book/website on patterns, look for the Observer
pattern, and see how that applies to you.

Cheers,
Jim Cooper

____________________________________________

Jim Cooper      jcoo...@tabdee.ltd.uk
Tabdee Ltd      http://www.tabdee.ltd.uk

TurboSync - Connecting Delphi with your Palm
____________________________________________

Re:Aggregate or Object Master-Detail question


Hi Jim

Thanks for your reply, I'll look at the observer pattern, and hope that I'll understand it :)

I'm sorry but I forgot to explain that the Postal Service is a service provider.

So the sender is our customer (as the user of our program) some of them have clientversion, and acts
as several senders (read departments)

The receiver is our customer's customer :)

So, what if the receiver list keeps a reference to the sender in the sender list, something like a
standard master-detail relationship ?

Quote
>Presumably, the list of receivers is not unique for each sender (eg the
>postal service could be a receiver for 2 or more senders)?

>In this case, I would not have the receivers "belong" to senders. I
>would have the senders keep a list of references to receivers. The
>normal way to do this is to create all the senders and receivers

I'm using D6 Pro - update 2 under Windows 2000
****************************************************
Best wishes
Kai Bohli
kaiboeNOS...@online.no
Norway
****************************************************

Re:Aggregate or Object Master-Detail question


Quote
> So, what if the receiver list keeps a reference to the sender in the sender list, something like a
> standard master-detail relationship ?

No. You want to avoid the sense that a receiver "owns" a sender (or vice
versa). In a database you might use a link table that has two foreign
keys.

If you are using objects then it is slightly different. Imagine you
create a list of objects (creating all the objects) representing the
receivers. Then you do the same with another list (again creating all
the objects) for the senders. Now, each receiver can have a list of
pointers (or object references, take you pick they're the same thing) to
the relevant senders.

Does that make sense?

Cheers,
Jim Cooper

____________________________________________

Jim Cooper      jcoo...@tabdee.ltd.uk
Tabdee Ltd      http://www.tabdee.ltd.uk

TurboSync - Connecting Delphi with your Palm
____________________________________________

Re:Aggregate or Object Master-Detail question


Thanks again Jim

Yes, I think I understand what you mean. Instead of keeping a link to the actual sender object, I
should use a pointer against the objects memory adress.

I'm grateful for your valuable tips. I'll keeps this in mind when I start out with this. It will be
good to begin programming again, after being degraded for several years as a "property setter" of a
lot of third-party db-aware controls :)

BTW - I found Joanny Carters website yesterday. I got a collection cd of UK-BUG, and there I found
more articled from her. She has a great talent for writing and does an excellent job of explaing
things like this in a way that's easy to grasp.

Quote
>If you are using objects then it is slightly different. Imagine you
>create a list of objects (creating all the objects) representing the
>receivers. Then you do the same with another list (again creating all
>the objects) for the senders. Now, each receiver can have a list of
>pointers (or object references, take you pick they're the same thing) to
>the relevant senders.

>Does that make sense?

I'm using D6 Pro - update 2 under Windows 2000
****************************************************
Best wishes
Kai Bohli
kaiboeNOS...@online.no
Norway
****************************************************

Re:Aggregate or Object Master-Detail question


I would design it like this:

[ Sender ] 1 <---------->0..n [ Package ] 0..n <---------------> 1
[Receiver]
                           |
|
                    [ CollectionInfo ]                            [
DeliveryInfo ]

In other words, the Sender class has a list of Packages (every package ever
sent by the Sender).
A Package must have 1 Sender and 1 Receiver.
The link between a Sender and a Package has an associated class,
CollectionInfo which stores things like the fee paid, the collection
address, collection time/date etc.
The link between a Receiver and a Package has an associated class,
DeliveryInfo which stores things like the delivery address, delivery
time/date, signature etc.

I'd recommend using Delphi 7 Architect, and its MDA architecture.  Once
you've learnt to use it you could build a back end to do this piece of your
puzzle in a couple of days.  Also take a look at www.neosight.com .  They
have an amazing product called BoldSynapse which makes it a doddle (set a
couple of properties in your diagram) to publish the backend as a set of Web
Services.  BoldRetina sits on top to build a web interface to the model.

Bryan

Quote
"Kai Bohli" <kai...@online.no> wrote in message

news:f596tukd2jhtbe4u0mha5u851meak7u1nb@4ax.com...
Quote
> Hi all !

> I'm wondering if someone could help me with advice on design of classes in
Delphi 6 ?

> Case:
> I'm working on a Transportation EDI (Electronic Data Interchange) app.

Currently we have the
Quote
> Norwwegian Postal Service in this app, but we're going to add several

others soon. This makes me
Quote
> realize that my app is too database oriented and it's not flexible enough.

> Problem:
> In our client version, several "senders" can send packages to several

"receivers" each. I have to
Quote
> make a lot of checks on the different values for each sender and receiver

before I allow the EDIFact
Quote
> message to be generated. This is why I want to create an object for each

sender and an object for
Quote
> each receiver.

> What I'm after:
> I would like to do something like this:
> 1) Create a list of objects holding each sender.
> 2) Create a list of receivers belonging to this sender

> How do I refer to the receiver that belongs to the sender. I mean: If I

move to the next sender, I
Quote
> should only see the receivers which belongs to that sender.

> Hope that I've explained properly, and that someone is willing to use his

valueable time to come
Quote
> with a suggestion.

> Thanks in advance.

> I'm using D6 Pro - update 2 under Windows 2000
> ****************************************************
> Best wishes
> Kai Bohli
> kaiboeNOS...@online.no
> Norway
> ****************************************************

Re:Aggregate or Object Master-Detail question


Quote
> Instead of keeping a link to the actual sender object, I
> should use a pointer against the objects memory adress.

They are the same thing. Eg

var
  MyObject1,MyObject2 : TMyObject;

MyObject1 := TMyObject.Create;
MyObject2 := MyObject1;

Now both MyObject1 and MyObject2 reference the same object.

Cheers,
Jim Cooper

____________________________________________

Jim Cooper      jcoo...@tabdee.ltd.uk
Tabdee Ltd      http://www.tabdee.ltd.uk

TurboSync - Connecting Delphi with your Palm
____________________________________________

Re:Aggregate or Object Master-Detail question


Hi Bryan!

Thanks for you suggestion, which looks very interesting. The problem with investigating stuff like
this is that the more you learn, the more you learn of what you should learn. :). Is any of D6's new
Colllection stuff any use here ? One things is certain, I need to learn to walk before I try to run
with designs like the one you suggested. So, I'll dig out the Delhi Magazine Collection CD, The
UK-BUG DIL cd and some books and search for OO stuff.

Quote
>I'd recommend using Delphi 7 Architect, and its MDA architecture.  Once
>you've learnt to use it you could build a back end to do this piece of your
>puzzle in a couple of days.  Also take a look at www.neosight.com .  

As much as I would love that, I'm afraid that it's out of the question. Hell, I consider myself
extremely lucky to have permission to use Delphi, since my boss uses Builder :). After using Builder
for 2 years, I regards Delphi as the true heaven - fast,easy and versatile unlike it's brother.

Your suggestion is highly appreciated and I'll take a closer look at it as soon as I've investigated
a bit more basic stuff.

I'm using D6 Pro - update 2 under Windows 2000
****************************************************
Best wishes
Kai Bohli
kaiboeNOS...@online.no
Norway
****************************************************

Other Threads