Main Page | Report this Page
Computers Forum Index  »  Computer - Object  »  A Design Pattern question...
Page 1 of 1    

A Design Pattern question...

Author Message
swen...
Posted: Sun May 24, 2009 8:03 pm
Guest
The situation is a IWinCallback which contains a method (MethodA) for aother
module to call back. There are three classes, ClassParent, ClassDerived1,
and ClassDerived2. ClassDerived1 and ClassDerived2 are derived from
ClassParent.

ClassDerived2 is instantiated inside ClassDerived1 when it needs to; other
times it is not instantiated at all. ClassDerived2 could be instantiated
alone sometimes.

In summary, there are three cases:

1. Only ClassDerived1 instantiates (ClassDerived2 does not).

2. Only ClassDerived2 instantiates.

3. Both ClassDerived1 and ClassDerived2 instantiate, and ClassDerived2 is
composed in ClassDerived1.

In all the above cases, the interface IWinCallback needs to exist. For each
case above, the MethodA in IWinCallback executes different code.
 
H. S. Lahman...
Posted: Mon May 25, 2009 7:26 pm
Guest
Responding to swen...

Quote:
The situation is a IWinCallback which contains a method (MethodA) for aother
module to call back. There are three classes, ClassParent, ClassDerived1,
and ClassDerived2. ClassDerived1 and ClassDerived2 are derived from
ClassParent.

ClassDerived2 is instantiated inside ClassDerived1 when it needs to; other
times it is not instantiated at all. ClassDerived2 could be instantiated
alone sometimes.

In summary, there are three cases:

1. Only ClassDerived1 instantiates (ClassDerived2 does not).

2. Only ClassDerived2 instantiates.

3. Both ClassDerived1 and ClassDerived2 instantiate, and ClassDerived2 is
composed in ClassDerived1.

In all the above cases, the interface IWinCallback needs to exist. For each
case above, the MethodA in IWinCallback executes different code.

I am not sure where the callback fits in. I assume methodA needs to
invoke a single callback from some other object but needs to do some
unique prep work for the call (e.g., gather arguments) that depends on
the flavor of [ClassParent] in hand.

If so I don't think it is a pattern; it is basic design. You need
objects in different classes to implement methodA differently and those
classes are each relevant only to one subclass of [ClassParent]. So...

[ClassParent]
A
| R1
+------+-------+
| |
[Derived1] [Derived2]
| 0..* | 0..*
| |
| R2 | R3
| |
| invokes | invokes
| 1 |1
[A1] [A2]
| |
+------+-------+
| R4
_
V
[CallbackStrategy]
+ methodA
| *
|
| R5
|
| invokes
| 1
[OtherClass]
+ callback

The R2 or R3 relationship is instantiated when the particular flavor of
[ClassParent] is instantiated. The [A1] and [A2] subclasses implement
methodA differently as subclasses while their superclass defines the
interface that the ClassParent in hand accesses.



--
Life is the only flaw in an otherwise perfect nonexistence
-- Schopenhauer

H. S. Lahman
H.lahman at (no spam) verizon.net
software blog: http://pathfinderpeople.blogs.com/hslahman/index.html
 
 
Page 1 of 1    
All times are GMT
The time now is Wed Nov 25, 2009 5:59 am