Subscribe to Java/SCJP        RSS Feed
-----

Abstract Factory Method Pattern

Icon Leave Comment
The Abstract factory pattern goes one level above in abstraction than Factory pattern. Here a concrete factory is provided for each concrete class and these concrete factories implement an abstract factory class. The advantage is that a single reference to abstract factory can be used to reference the concrete factories. This way all concrete classes have their own factories (they were not segregated in factory pattern).

e.g.
abstract class AbstractFactory{
static AbstractFactory getFactory();
}

class Factory1 extends AbstractFactory{
getInstance(return (new Instance1));
}

class Factory2 extends AbstractFactory{
getInstance(return (new Instance2));
}

interface SomeInterface{
}

class Instance1 implements SomeInterface{
}

class Instance2 implements SomeInterface{
}

class Requester{
AbstractFactory abstfact = new Factory1();
abstfact.getInstance();
abstfact = new Factory2();
}

0 Comments On This Entry

 

January 2022

S M T W T F S
      1
2345678
9101112131415
161718192021 22
23242526272829
3031     

Recent Entries

Recent Comments

Search My Blog

11 user(s) viewing

11 Guests
0 member(s)
0 anonymous member(s)