Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I was looking for a pattern/solution that allows me call a method as a runtime exception in a group of different methods without using Reflection. I've recently become aware of the Abstract Factory Pattern.

To me, it looks so much like polymorphism, and I thought it could be a case of polymorphism but without the super class GUIFactory, as you can see in the example of the link above. Am I correct in this assumption?

share|improve this question
    
What WidgetFactory? –  Yannis Rizos Nov 29 '11 at 1:23
    
Check this out: en.wikipedia.org/wiki/Abstract_factory_pattern –  rogcg Nov 29 '11 at 14:09
    
Yes I've seen the article, there's no WidgetFactory class. Did you mean GUIFactory? –  Yannis Rizos Nov 29 '11 at 14:15
    
Correct, GUIFactory. –  rogcg Nov 30 '11 at 19:36

1 Answer 1

up vote 5 down vote accepted

I guess it depends on how it is used.

Essentially the Factory pattern is a reference to a set of objects. Normally combined with something else, possibly like the Strategy pattern (which is more likely to be defined as a type of polymorphism) to provide reference to an object to act on.

The Abstract Factory Pattern by itself is intended to be polymorphic as it is defined as an abstract class type. However the concrete implementation of the factory is the WidgetFactory in your type and is only polymorphic in reference to using a factory and providing an implementation of a factory.

In terms of what you are after, you certainly require a concrete factory, and presumably the actions you perform depend on the exception being caught. To that end you would use your factory implementation in a non-polymorphic way simply by passing it the exception caught, and have the factory pattern return a method to invoke a strategy or even a chain-of-command pattern to deal with how you would like to handle the exception.

Therefore, your factory would not necessarily be polymorphic, and your exception handlers would be polymorphic.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.