Exclusive VS Shared Collections

Discussions about design and architecture principles, including native JADE systems and JADE interoperating with other technologies
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Exclusive VS Shared Collections

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:17 am

by Joseph O'Dwyer >> Thu, 2 Dec 1999 23:05:04 GMT

I would like to know more about when to use a Shared collection instead of an Exclusive collection. Also some examples of where Shared collection should be used and how they are maintained.

Thank You

Joseph O'Dwyer

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Exclusive VS Shared Collections

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:17 am

by Dean Cooper >> Wed, 8 Dec 1999 1:48:58 GMT
I would like to know more about when to use a Shared collection instead of an Exclusive collection. Also some examples of where Shared collection should be used and how they are maintained.

Shared collections are used mainly for working storage or computational purposes; eg: building the results of a query, sorting a collection of objects for processing, or for passing a collection of objects around (between methods or nodes or forms). In your object model (especially your persistent model), exclusive collections should be the rule; shared collections the exception. And there should be few cases where your exclusive collections don't have at least one inverse (referential integrity, and automatic maintenance of collection members and dictionary keys should be justification enough to define inverses). A shared collection cannot be used to implement the "many" end of a relationship.

Shared collections are required only when a collection can have more than one owner (ie: when several objects need to hold a reference to the collection). Otherwise exclusive collections are more convenient. Even if you have a collection (eg: a conversion table) to which many parts of your system require access, typically this will be owned by some higher-level parent object (ultimately your top-level root object, or perhaps app or global). In cases where you can always obtain a reference to the owner object, it makes sense for the collection to be exclusive. Also it's common for this owner object to provide methods that encapsulate the collection, rather than have other objects access it directly.

One notable exception to this is when you want to have a collection of collections (eg: a multi-dimensional array). Exclusive objects cannot be added to a collection as this would violate their exclusivity. For a collection of collections, the container collection may be shared or exclusive, but the collections being added to the container collection must be shared (FAQ 13985 at news.jadeworld.com discusses a multi-dimensional string array).

Regarding maintenance: Like any collection that doesn't participate in a relationship (ie: doesn't have inverses), no automatic maintenance is performed for shared collections. This means that once you've added an object to a shared collection, if that object is deleted, your application must handle maintaining the collection. If it's a shared dictionary, your application must handle maintaining it if the keys of any of its member objects are changed (you need to remove the object from the dictionary, change the keys, and then add it back). Both member and key maintenance is performed automatically by the kernel for exclusive collections with inverses.

Dean.


Return to “Design and Architecture”

Who is online

Users browsing this forum: No registered users and 11 guests

cron