Doing AbstractFactory using VB's Implements Keyword? 
Author Message
 Doing AbstractFactory using VB's Implements Keyword?

Hello All,

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

and the following concrete classes (using the Implements keyword in VB):

CMyFactory
CMyProductA
CMyProductB.

All is OK so far.  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.

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?

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?

Many thanks for reading this far, and for any help or insight you can give,

Regards,

Steve M.



Thu, 16 Aug 2001 03:00:00 GMT  
 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.



Thu, 16 Aug 2001 03:00:00 GMT  
 Doing AbstractFactory using VB's Implements Keyword?

Quote:
> Hello All,

> 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...


quiet.

there's a good write up of an observer pattern in vb at:
http://www.digitalanswers.com/Notification/

here's a singleton pattern that may help:

Quote:

> If you put the singleton in a constructor you may lose the power of
late
> binding.

> Here is the way we implement Singletons in VB in my shop (thanks to
Doug
> Finke). In this VB example, theBulkCopy is a public method that
returns the
> value of a Private member, mtheBulkCopy

> Option Explicit

> Private mtheBulkCopy As BulkCopy
> Private mtheSQLServer As SQLServer
> Private mtheIMCBCPInfo As IBCPInfo

> Public Function theBulkCopy() As BulkCopy
>     If mtheBulkCopy Is Nothing Then
>        Set mtheBulkCopy = New BulkCopy
>     End If
>     Set theBulkCopy = mtheBulkCopy
> End Function

> Public Function theSQLServer() As SQLServer
>     If mtheSQLServer Is Nothing Then
>         Set mtheSQLServer = New SQLServer
>     End If
>     Set theSQLServer = mtheSQLServer
> End Function

> Jane Warsaw
> Technical Director, Proxicom, Inc.
> 55 Broad Street, NY, NY 10004
> 212-363-6580 x 3063, 212-363-6522 (FAX)
> http://www.proxicom.com <http://www.proxicom.com>

hth

--
Ray (will hack java for food) http://home.pacbell.net/rtayek/
hate Spam? http://www.blighty.com/products/spade/



Fri, 17 Aug 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. 'Implements' keyword

2. Problems with polymorphism in VB5.0 when using keyword Implements

3. Polymorphism using the Implements Keyword

4. Implements keyword, using properties

5. Using the 'LIKE' keyword

6. Implements keyword failing *sometimes*

7. Implements keyword

8. Implements Keyword in VBA

9. Critique of Implements keyword

10. VB6 does not maintain binary compatibility with VB5 projects that use Implements keyword

11. Trouble with "Implements" keyword

12. Implements keyword & Events

 

 
Powered by phpBB® Forum Software