In search of Pattern

I have a situation here and I havent been able to conceptualize a good solution.

Background

I have an object that processes changes in things that contribute to changes. And then I have this system of objects.

Architecture

System

Component

ComponentInstance

The architecture does not really change, its more the 'scope' of the changes. Architecture can contain 0..n systems. System can contain 0..n ComponentInstances. A Component instance is an instance of a Component within a given system. A component can have instances in different systems, can have multiple instances in the same system, and a component can have instances in systems of different architectures.

Problem

Now the problem is with Component. The architecture only cares about changes to a component if the component has ComponentInstance(s) in one of the architecture's systems. So when a ComponentInstance is added to a system, I need to start listening to the Component. and if the last ComponentInstance of the Component is removed from the system, i need to stop listening to the component.

The quick and dirty solution seems to be an instance counter. When a ComponentInstance is added to a system, ill listen to the Component, and increment a counter indicating how may ComponentInstances of that Component are in the system. And decrement as they are removed. When it reaches 0, ill stop listening to the component.

It just seems dirty. The problem seems so complicated that the whole system seems a bit dirty. However, it started out as much cleaner than the one its replacing. This part is not looking good though. I hate keeping a map of the count of ComponentInstances of a particular Component.

[1765 byte] By [_dnoyeBa] at [2007-10-2 22:42:12]
# 1
well i just pushed through it and made it work. Ill refactor it over next few months I suppose till it looks clean...I think writing it down helped.
_dnoyeBa at 2007-7-14 5:56:35 > top of Java-index,Other Topics,Patterns & OO Design...