|
| Circular Reference & Redesign |
 |
Tue, 8 Apr 2008 08:46:00 -0400 |
I need to move code which is in one unit and place into multiple units but I
am having circular reference problems.
Background:
I have an image editor, mouse actions are implemented by different "mouse
handler" classes. For instance if I need to Paint then I intantiate a
"Paint" mouse handler and all mouse actions on the image are handled
by that
class. When I need to do something else like copy then I instantaite and
use a "Copy" mouse handler. Each handler has a reference to the form.
But,
the form also has a reference to some specific mouse handler instances.
I want to move these mouse handlers out to separate units and get them out
of the form unit but I have circular reference problems that must be
resolved. What pattern or redesign would you suggest?
-Bill
|
| Post Reply
|
| Re: Circular Reference & Redesign |
 |
Tue, 8 Apr 2008 09:07:14 -0400 |
On Tue, 8 Apr 2008 08:46:00 -0400, William Egge wrote:
> I want to move these mouse handlers out to separate units and get them out
> of the form unit but I have circular reference problems that must be
> resolved. What pattern or redesign would you suggest?
I would probably create an abstract mouse handler, either in the form
unit or a separate unit and then have all the handlers subclass that,
then the form only needs to be aware of the abstract base class.
--
Marc Rohloff [TeamB]
|
| Post Reply
|
| Re: Circular Reference & Redesign |
 |
Tue, 8 Apr 2008 09:34:00 -0400 |
> I would probably create an abstract mouse handler, either in the form
> unit or a separate unit and then have all the handlers subclass that,
> then the form only needs to be aware of the abstract base class.
This is how it is now, but the abstract class has a reference to the form
class and then the form class has a reference to one of the mouse handler
subclasses.
|
| Post Reply
|
| Re: Circular Reference & Redesign |
 |
Tue, 8 Apr 2008 11:06:53 -0400 |
On Tue, 8 Apr 2008 09:34:00 -0400, William Egge wrote:
> This is how it is now, but the abstract class has a reference to the form
> class
I have generally found it simpler to not give the base class a
reference to the form.
> and then the form class has a reference to one of the mouse handler
> subclasses.
However it should be assigning it to a field of the abstract class
type so the form will use the abstract handler's unit in its interface
section and the concrete classes' units in its implementation section
which would not cause a circular reference.
--
Marc Rohloff [TeamB]
|
| Post Reply
|
| Re: Circular Reference & Redesign |
 |
Tue, 8 Apr 2008 14:41:59 +0100 |
> This is how it is now, but the abstract class has a reference to the form
> class and then the form class has a reference to one of the mouse handler
> subclasses.
Sounds dodgy :-) Use an interface.
|
| Post Reply
|
|
|
|
|
|
|
|
|
|