Select to view content in your preferred language

IApplication object passing - why this object model?

499
2
07-30-2010 11:05 AM
ScottBrown
Deactivated User
Hi all,

This is my first time posting to these forms.  I have what I believe is a simple but foundational question concerning the object model at use in ArcObjects / for ArcMap tools.

I've noticed that just about every UI-related method in the .NET/C# API expects an IApplication object.  Call it an overly simple question, but why is this?  I'm writing an extension to ArcMap, and in doing so I have never noticed the IApplication object change.  Isn't this ripe for a singleton object?

As usual with design questions, I assume that their decision was well informed and that I am not.  Are there circumstances where a single code base can run against multiple applications?  Can the IApplication object be reallocated at run time?  Is this related to some detail about COM object programming with which I am not familiar?

I'd appreciate any illumination you could offer, thanks!

- Scott
0 Kudos
2 Replies
AndrewMay
Emerging Contributor
Hi Scott
Thought I'd replied to this the other day but it seems to have vanished...

The Application object will change, for example IApplication::Document will change when you open a new mxd.  Though admittedly most of the properties do stay the same.  Also you can have multiple instance of Arc running at one time so you could potentially have references to both of these applications, for example if you want to check if another instance is running or not.

As for singleton classes...that's probably a discussion for another day but I think you'll find plenty of people who think they're best avoided.

Hope this helps
0 Kudos
ScottBrown
Deactivated User
Thanks Andrew - that's quite helpful.
0 Kudos