Author Topic: Stumped! Generalised object creation aka late bind  (Read 4414 times)

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Stumped! Generalised object creation aka late bind
« on: March 28, 2004, 09:58:41 pm »
 ???

In a communication diagram how do you folks show the creation of a late bound object?  

For example:

Dim Repo as object
Set Repo = CreateObject("EA.Repository")
etc

The thing gets even more complex if the object is declared as a global as the creating class then cant even be said to "own" the object.

Once the object exists, associations and collaborations all make sense, e.g.
Repo.OpenFile(MyPath)
can be sensibly modelled as a collaboration message between the OpenEAFile button and the object.

But having an association between the "Connection" button and the Repo object and a "CreateMe" message doesn't IMHO make sense as now we have class methods and conceptual methods on the same diagram.

                                                                                               create>
[Connection]--------------------------[Repo]
                                                                                                                                                                                                                                            |
[OpenEAFile]------------------------------|
                                                                     OpenFile(filepath)>




So I'm after a bit of best practice advice.
tia
Bruce
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Stumped! Generalised object creation aka late
« Reply #1 on: April 01, 2004, 03:00:41 pm »
No takers?  Let me try again.

The intent of the messages between objects on a communication diagram is that they (ulitmately) end up as methods of the target element classifier.  Right?

So if ObjectA:Class1 sends a message to ObjectB:Class2 then we will end up with some method in Class2 that implements the message.  Right?

If ObjectA actually creates an instance of ObjectB then the message is the constructor of Class2. Right?

i.e.
Code: [Select]

   private MyNamespace.Class2 ObjectB;
   
   this.ObjectB = new MyNamespace.Class2();

This is fine.  ObjectB is early bound and the constructor message can be modelled in a communication diagram.


[ObjectA]
        |-------new----> [ObjectB]
        |                                                                                                                    |
etc

I can easily see who is the creator of ObjectB and when it is created.

But with late bound objects, I cant see how I can link them to the object they are created by - they are not using (to my mind) the constructor of ClassB  - they are using some framework level constructor of a generalised object that is cast ???

That is the message from ObjectA is not the "new" message in the above artwork.  It seems to be some kind of "virtual" message to the framework to create an anonymous object that I will, at runtime, stick a Class2 object into.

1) Am I right?  
2) If so, how do I draw this?

sorry to re-interupt.
Bruce
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

jkorman

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Re: Stumped! Generalised object creation aka late
« Reply #2 on: April 01, 2004, 08:26:15 pm »
Bruce, Maybe I'm not getting what you're after but  how about.....

You will be given a crayon and paper.
You don't really care who created them.
You take your "given" crayon and paper and model the associations
and behaviors you expect them to have when you have them.

That's the same approach I use when looking at a class instance
provided by a factory method. I don't know, and may not actually care,
the exact type but only that what I was given implements the published
contract for the base class.

> If ObjectA actually creates an instance of ObjectB then the message is the constructor of Class2. Right?
ObjectA may have participated in the creation of ObjectB or it may have come out of a pool, or been
created by the Easter Bunny  ;)  You may not need to know, and may even be kept from knowing how
the instance came into being, its there ready for you to use. Enjoy.

Jim

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Stumped! Generalised object creation aka late
« Reply #3 on: April 01, 2004, 08:50:58 pm »
Harumph!  

Quote
You don't really care who created them.


OK, your probably right there. But my problem is when they are created.

I am probably being too "pure" as you indicate.  I think I'll just stick a <<virtual>> message in to create the thingies when they need/should appear in the timeline.

B
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

Stephen

  • EA User
  • **
  • Posts: 54
  • Karma: +0/-0
    • View Profile
Re: Stumped! Generalised object creation aka late
« Reply #4 on: April 02, 2004, 07:09:38 am »
Bruce,

Bear with while I try to get up to speed. My modelling skills are woeful :(, but if I don't try to understand they're not going to get any better are they?

My basic understanding was that communication diagrams are used to "... show the behaviour of several objects collaborating together to fulfill a common purpose" (Scott Ambler, www.agilemodeling.com/artifacts/collaborationDiagram.htm - also see www.agilemodeling.com/artifacts/collaborationDiagram.htm).
If we accept the statement and put our algorithm logic in a complementary sequence diagram (which would show object lifetime - a pre-existing object would just be live throughout the diagram), then I wouldn't expect to see any creator/destructor style messages in the collaboration diagram.... The object is assumed to be present to participate in the collaborative effort.

message to self.....
I must get beyond class diagrams
I must get beyond class diagrams
I must get beyond class diagrams

Stephen

Stephen

  • EA User
  • **
  • Posts: 54
  • Karma: +0/-0
    • View Profile
Re: Stumped! Generalised object creation aka late
« Reply #5 on: April 02, 2004, 08:10:15 am »
errata!
Second Scott Ambler link should have been http://www.agilemodeling.com/style/collaborationDiagram.htm

But that still doesn't address your concern around distinguishing late binding from early binding
Must be using the wrong model.
Sequence diagram feels right but.... took me half an hour to get this little example right - can't be worth it
- perhaps I ought to practice drawing these a little more often    ;)

Stephen

D**n - How do you get a picture in here, I've seen others...Can't believe I've wasted all that time...

jkorman

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Re: Stumped! Generalised object creation aka late
« Reply #6 on: April 02, 2004, 08:56:04 am »
to embed an image

lbracket img rbracket url_of_file lbracket /img rbracket

now how do you escape the brackets so you can use them?

Jim