Monday 12 March 2007

The Abstract Factory

Task 1 – Abstract Factory

In this lecture we looked at the Abstract Factory design pattern. In this blog I discuss my understanding of the Abstract Factory

Definition 1

Abstract Factory is a set of related abstract classes, the Abstract Factory pattern provides a way to create instance of those abstract class from a matched set of concrete subclasses. This pattern is useful for allowing a program to work with a variety of complex external entities such as different windowing systems with similar functionality.[1]

Definition 2

Abstract Factory pattern can also be defined as a design pattern that provide an interface for creating families of related or dependent objects without specifying their concrete classes.[2]

The link to reference [2] provides a good structure of the Abstract Factory together with the code.

In Abstract Factory, the client does not know (or care) about which concrete objects it gets from each of these internal factories since it uses only the generic interfaces of their products. This pattern separates the details of implementation of a set of objects from its general usage.

A good example of when the Abstract Factory should be used is when a system needs to support multiple look-and-feel for the user interface for example Windows 9x, Motif, and Macintosh. The same application will have different look and feel under different platforms without the need to change the core of the application.

A non software illustration of Abstract Factory design pattern

In the sheet metal stamping equipment used in the manufacture automobiles, the stamping equipment is an Abstract Factory. It creates auto body parts. The same machinery is used to stamp right hand doors, left hand doors, right front fenders, left front fenders, hoods, etc. for different models of cars. Through the use of rollers to change the stamping dies, the concrete classes produced by the machinery can be changed within three minutes. [Michael Duell, "Non-software examples of software design patterns", Object Magazine, Jul 97, p54]

Advantages of using Abstract Factory

  • The Abstract Factory isolates the concrete classes from the abstract classes that generated them. Because of the isolation of classes, you can change or interchange
    The product class families freely.

  • Further, since one generates only one kind of concrete class, this system avoids from inadvertently using classes from different families of products.


    Disadvantages of using Abstract Factory
  • There is nothing to prevent some derived classes from having
    additional methods that differ from the methods of other classes.


    Related Patterns

    1. Factory Method
    2. Singleton: Concrete Factory classes are usually implemented as Singleton classes

    Task 2

    Examining the Coursework and critiquing it.

    The lecturer asked us to examine the Coursework and critique it.

    The coursework has something for every one, both programmers and non-programmers. Task 1 can easily be handled by both programmers and non-programmer. Programmers may not have problems with Task 2 especially if Task 1 was well handled.

    However, in case Task 1 is not efficiently do, results in Task 2 may be badly affected. To attempt Task 2 would require one to have do Task 1 pretty well. It would also be difficult to do Task 2 without doing Task 1.

    It also put to use the skills previously learned for example the use of UML. One can therefore apply skills previously learned.

    The blog is quite an interesting one. From the blogs I have done so far and from commenting on other people’s blogs, I have learnt a lot about Design Patterns. It also makes the subject interesting. The blog is funny!!

    To understand patterns even better, the course work requires/covers anti-patterns. Being a subject about Patterns I had not expected to find Anti-patterns being mentioned at all. However studying patterns and anti-patterns gives an appreciation of the two concepts. One can there for better understand them.

    Task 3 further cements the understanding of Design Pattern by allowing students form complete patterns from a list of incomplete ones. This gives a practical dimensional to the subject which would have rather been too theoretical.

    However the word limit on the essay seems to be tight, given the kind of discussion this will be.

References:


[1] Mindspring.com
Overview of Patterns
(2007)
http://www.mindspring.com/~mgrand/pattern_synopses.htm#Abstract%20Factory
Accessed 2nd March 2007

[2] Data and Object Factory
Abstract Factory
http://www.dofactory.com/Patterns/PatternAbstract.aspx
(2007)
Accessed 2nd March 2007

6 comments:

Abbas said...

well explained, Few more advantages of Abstract factory are;

Isolation of concrete classes; they becoming independent of how the system is implemented from client side

exchangin of different families of products because easy because they all belong to same set

Bash said...

I must say that you have done a very good job in researching on Design Patterns.
There is another disadvantage of The Abstract Factory Pattern, which is that it is difficult to extend this pattern to produce new kind of products.

Unknown said...

hi, thank you for your comment,appreciate it. i was more concerntrating on comparing the two book i have choosen to learn about Abstract Factory pattern and suggesting which one to go if any student what to learn about patterns.

John Ssebaale said...

Hi Abbas thank for the additional input. the additional advantages you added were cool! I do appreciate.

John Ssebaale said...

Hi Bash thanks for the disadvantage of Abstract Factory pattern you highligted. It is great. When you highlighted it, I did some reading about it in the GOF book, it was great! thanks for the comment

Daljit @ Dil said...

Good work John.

A quick add on to the disadvantages of the Abstract Factory Pattern is that the users/clients must know to use the factory rather than just creating objects/constructor.

Goodday.