Re: Properties Shared Amongst Objects
- From: Robert Martin <unclebob@xxxxxxxxxxxxxxxx>
- Date: Mon, 18 Feb 2008 10:09:15 -0600
On 2008-02-17 03:22:37 -0600, "Leslie Sanford" <jabberdabber@xxxxxxxxxxxxxxxxx> said:
In an application I'm writing, I have a group of objects that are instances
of the same class. These objects share the same property values.
...
My approach was to factor out properties into classes of their own.
Instances of the property classes are passed to component objects.
...
In some cases components need to know when a property changes value. I've
set up a simple implementation of Observer so that components can hook into
properties in order to receive notification of value changes.
I'm looking for comments or insights into the above approach. Also, are
there any sources that describe an approach similar to the above?
This is a very common approach, especially in data flow applications.
The things to worry about:
1. The cost of indirection. Each component touches it's properties through a pointer instead of as a value. This is a tiny overhead; but could add up if you have millions of nodes.
2. Avoid duplicate update. Since properties are shared between components, you may need to avoid updating a single property more than once if two components sharing that property are updated separately.
3. The cost of observers. Watch out that you don't burn cycles checking for observers that don't exist. Use a polymorphic dispatch for NothingObserved.
4. Observers can be hard to manage. You have to be able to register, and de-register. Push model observers are usually more efficient than pull model observers; but it's not always clear what to push.
5. Memory management. It looks like you are using C++. Cleaning up the properties when a component is destroyed can be tricky. Other components may still be using those properties. A reference counting approach is probably best.
That's all I can think of at the moment.
--
Robert C. Martin (Uncle Bob) | email: unclebob@xxxxxxxxxxxxxxxx
Object Mentor Inc. | blog: www.butunclebob.com
The Agile Transition Experts | web: www.objectmentor.com
800-338-6716 |
.
- References:
- Properties Shared Amongst Objects
- From: Leslie Sanford
- Properties Shared Amongst Objects
- Prev by Date: Re: OO Methodolgy Perspective
- Next by Date: Re: OO Methodolgy Perspective (was Re: OOSE is outdated ?)
- Previous by thread: Re: Properties Shared Amongst Objects
- Index(es):