A: 

I would allow the ButtonPad to create its own ComInstance. I note in your sequence diagram, that the ButtonPad is the only object that touches the ComInstance. So keep it internal.

John Saunders
There are more objects in my library then just button pad, so that's why I pass it in.
Nathan W
And they all use the same ComInstance?
John Saunders
Yep. I'm making a .NET SDK for a mapping program which only exposes to methods one takes a string and one takes a string and returns the result as guess what a string. :( So I'm making a OO wrapper over the top of a procedural scripting based program.
Nathan W
So, what's the ComInstance - the mapping program?
John Saunders
Yep. The user creates the instance then passes it into each wrapper layer.
Nathan W
Ok, yeah, that's a bad design. You've got your UI controls doing work. UI controls should do UI, and should inform an application that then does work. "Separation of Concerns".
John Saunders
How would you lay it out? What the user needs to be able to do is change the title of the button pad after it's been created in the COM object and reflect that change in the COM object. Maybe I should have button pad colection that you can add the button pad to that creates the button pad, but then you still have the how to update the pad after created problem.
Nathan W
Does your ButtonPad present its own UI, or is it the COM object that does the UI, and ButtonPad is just a .NET Wrapper around it? Does the COM object have more UI than just the ButtonPad? Other wrapper controls? Also, I presume the COM object does UI and also has methods that do things?
John Saunders
The com object does the UI, and Button pad is just a wrapper around it. Yeah it has more UI then just the button pads. The com object just has two methods Do and Eval, so I say Do("Create ButtonPad") and when I want to alter an exsiting one I do Do("Alter ButtonPad...some properties"). Everything is run on the Com object through these two commands. The main thing is I want to make my wrapper feel like OO with turning into a bunch of procedural calls because of the underlying commands. Sorry about doing all this in the comments, I'll draw picture that show it.
Nathan W
*without turning into a bunch of procedural calls because of the underlying commands.
Nathan W
A: 

I would agree with John's answer.

The other alternative would be to replicate the internal state of the ButtonPad to the COM Object when you instantiate it.

ie: Option 1 (John's) is to create the COM Object from the ButtonPad constructor.

Option 2 is to reflect the state of ButtonPad to the COM Object inside ButtonPad.CreatePad(...). ButtonPad.CreatePad(...) would then call CreateButtonPad on the COM object, and then call SetTitle(), etc. on the COM Object before returning so that ButtonPad ensures that the state of the COM Object is consistent.

I would prefer option 2 if it makes sense for the ButtonPad to exist without the COM Object, or possibly if you didn't have access to the IComObject required to instantiate the COM Object at the time the ButtonPad is instantiated. Otherwise I'd go with option 1.

Phil
A: 

I'd first ask: what's the use case for manipulating ButtonPad properties independently of the underlying properties that they're hiding? There are most likely two answers for that: 1) there isn't one, 2) it's critically important that we be able to do that.

The answer in the first case is pretty straightforward: create the underlying COM object in your class's constructor, map your properties onto its properties, and call it a day.

In the second case, though, you're getting into territory that smells a lot like data binding. You have a data source (your object), the thing it's bound to (the COM object), the need to convert property values between the two things (i.e. parsing and formatting, if the communication is two-way), and possibly even a need for mapping property changes through event notifications. (Like, if something else manipulates a property of the COM object, does your .NET object need to be notified?)

I'm not saying that you'd actually want to use binding to do this, but I'd certainly look at the way .NET data binding is designed and see how many pieces of that design you actually are going to need.

In all likelihood, you'll look at it and say "Wow, that's really complicated." That's because what you're trying to do is fundamentally really complicated. It's a lot more complicated if your design doesn't implement separation of concerns.

Robert Rossney