CSE687 - Object Oriented Design

Design Note #7
Power and Perils of Sharing

Revised: 4/28/2011
Home Courses Code Handouts CoreTech Books Articles Math Research Masters Projects SWDev WebDev News OtherLinks SiteDesign Graduates AllPages Office Hours Notices

CSE681-SWMAA CSE686-IP CSE687-OOD CSE775-DO CSE776-DP CSE778-AWP CSE784-SWS

Cncp #01 Cncp #02 Cncp #03 Cncp #04 Cncp #05 Cncp #06 Cncp #07 Cncp #08 Cncp #09 Cncp #10 Cncp #11
Note #01 Note #02 Note #03 Note #04 Note #05 Note #06 Note #07 Note #08
Lang #01 Lang #02 Lang #03 Lang #04

Syllabus SG - Design SG - Templates SG - Class Relationships

Design Note #7:

Sharing of information and resources is one of the most important things our applications do. There are several types of sharing that are quite common in applications being built today: But the benefits of sharing come with costs and problems. One client may make changes that adversely affect another. Two clients may attempt to concurrently acquire a resouce causing one to block or perhaps corrupting the state of the resource. Proprietary or secret information may be inadvertently disclosed through sharing of resources.

Conclusions for: Power and Perils of Sharing

Your applications will share user information, external information from stored data, resources like streams, files, queues, and memory.
  1. Do the least amount of sharing possible and still provide the application's functionality.
  2. When you allocate shared resources like files, streams, and database locks, release them as soon as you have finished. Your design should strive to make the duration of use as small as possible.
  3. Return shared resources, when you've finished, in the same state you found them, unless every single user agrees that the modifications are intended and expected.
  4. Keep sharing between theads localized and simple as possible. Sharing through carefully constructed thread-safe containers like Blocking Queues makes threaded designs managable.