Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[wtp-dev] Proposed new pattern for managed models (was "Re: Scary code")

Naci Dai wrote ....
>There is something that makes me uneasy about the following code...
>core = StructureEdit.getStructureEditForRead(projects[i]);

>some stufff
>This is very open to making mistakes (i.e unbalanced dispose). I do not have

>an answer to an alternative, try-finally is a clumsy workaround,
>but I have a feeling this bug will also be a pattern.

I'm not sure our SSE ModelManager is the only reason for this pattern,
but it is one.

The model provided is a "shared resource" so, it is appropriate for clients to
be required to use a try {} finally{} pattern to ensure proper acquisition and
release. But ... it is admittedly a problem area and often prone to bugs.

To help address this, part of our proposed API change (for next milestone) will be to move to
a pattern something like

connect(requester, IPath)

model = getModel(IPath)

disconnect(requester, IPath).

A try/finally pattern will still be required (and is still appropriate) ... but
1) it is similar to the base eclipse's
pattern in IFileBufferManager ... so maybe more familar to Eclipse programmers? (or, is
at least one problematic pattern instead of two :),  and
2) the presense of 'requester' on the call will allow for improved debugging messages
(eventually) [thanks to Jason Sholl for this suggestion]

Thought I'd post these ideas here now, instead of waiting till whole design change
documented, in case there was any wtp developer comment or implications we
should be aware of.

Thanks for the discussion.

Back to the top