
Doing AbstractFactory using VB's Implements Keyword?
Quote:
>Hello All,
Hello one.
Quote:
>Can anyone help me with the following?
>After getting a copy of the excellent "Design Patterns" book, I decided to
>try to use the AbstractFactory pattern in VB...
>I have the following interface classes:
>IAbstractFactory (with CreateProdA and CreateProdB operations)
>IAbstractProductA
>IAbstractProductB
Usually, a factory produces objects conforming to
the same abstract interface. I think part of your
problem is that you are defining separate abstract
interfaces for the possible products. I do not see
what type of interface variable you expect to assign
the factory output to.
Quote:
>and the following concrete classes (using the Implements keyword in VB):
>CMyFactory
>CMyProductA
>CMyProductB.
>All is OK so far.
I think the trouble is already started.
Quote:
>But my problem is that part of the interface for ProductA
>and ProductB is the same... for instance they both contain (Draw and Rotate
>operations), so I'd like to create an interface for these operations and
>have my products implement that interface.
>I'd like to be able to have my factory class create products that are
>related by part of their interface.
Typically, when objects are used polymorphically,
they share all the methods of the polymorphic
interface, not just some of them. (The interface
is coexistent with the set of abstract operations,
so it is a bit of a misnomer to say "part of the
interface is the same".)
Quote:
>My questions are:
>1) Is AbstractFactory supposed to be used in this way? Ie should ProductA
>and ProductB be completely different types? Or should I be using a
>different design pattern in this case?
I am unsure what design pattern you actually intend
to use here, but here is the one I think you want:
- Define an interface that includes the features
common across all the objects to be produced
by the factory and which should be exposed
to clients of the factory. Call this the abstract
client interface.
- Define implementation classes which are to
implement that interface. This is exactly what
the VB Implements feature is designed for.
- Have your factory instantiate one of those
implementation classes to be returned as an
object providing the abstract client interface.
Quote:
>2) If I want to do this in VB, I run into problems with the "Implements"
>keyword: It seems that an interface cannot iherit from another interface?
>Is this true? Do I have to resort to delegation?
It is true that VB does not support interface
inheritence with extension of the interface.
With the "Implements" feature, it supports
interface inheritance without extension. As
of the latest released version, VB does not
support implementation inheritance and so
that has to be simulated via delegation.
Quote:
>Many thanks for reading this far, and for any help or insight you can give,
If you can reformulate your problem as
"multiple implementations of the same
abstract interface", then I think I may
have contributed an insight here. If not,
I must admit befuddlement as to what
you are trying to accomplish.
--Larry Brasfield
Above opinions may be mine alone.