Abstract Factory

The abstract factory pattern

The abstract factory pattern is a creational pattern [GOF], which is a pattern classification concerned with flexible object building.
The way in which it's organised will drive you quite mad as it's quite a confusing pattern and, if used, should be well documented for the next developers.

Firstly, we make an abstraction of the factory, and the different methods required to build our complex object:
abstract class LayoutFactory {
    public abstract ContainerBox CreateContainerBox();
    public abstract MenuBar CreateMenuBar();
}

Similarly, to the factory method pattern, the underlying abstract class can't be changed, as this would lead to an avalanche of changes to the other dependent classes.
We define abstractions for the Create... methods:
abstract class ContainerBox {
    public void Contains(MenuBar menuBar) {
        Console.WriteLine(this.GetType().Name +" contains " + menuBar.GetType().Name);
    }
}
and (simply)
abstract class MenuBar {
}

We then implement the original contract and the abstract classes that it depends upon:
class PlainLayout : LayoutFactory {
    public override ContainerBox CreateContainerBox() {
        return new PlainContainerBox();
    }
    public override MenuBar CreateMenuBar() {
        return new PlainMenuBar();
    }
}

And another implementation:
class FancyLayout : LayoutFactory {
    public override ContainerBox CreateContainerBox() {
        return new FancyContainerBox();
    }
    public override MenuBar CreateMenuBar() {
        return new FancyMenuBar();
    }
}
I've skipped the implementations of Create... methods as they don't do much in this example, the complete code is here.

The code to run this example is:
static void Main(string[] args) {

    LayoutFactory plainLayout = new PlainLayout();
    ContainerBox plainContainerBox = plainLayout.CreateContainerBox();
    MenuBar plainMenuBar = plainLayout.CreateMenuBar();

    plainContainerBox.Contains(plainMenuBar);

    LayoutFactory fancyLayout = new FancyLayout();
    ContainerBox fancyContainerBox = fancyLayout.CreateContainerBox();
    MenuBar fancyMenuBar = fancyLayout.CreateMenuBar();

    fancyContainerBox.Contains(fancyMenuBar);

    Console.ReadKey();
}
The output being:
PlainContainerBox contains PlainMenuBar
FancyContainerBox contains FancyMenuBar

The pattern has room for the factory method pattern, as, for example, different methods could have concrete implementations within the structure.

Is this Unit Testable? Yes it is, both the abstract and concrete implementations could accept the instantiations through contructors or setter methods.
The code changing, for the FancyLayout class, to:
class FancyLayout : LayoutFactory {
    private ContainerBox fancyContainerBox;
    private MenuBar fancyMenuBar;

    public FancyLayout(ContainerBox fancyContainerBox, MenuBar fancyMenuBar) {
        this.fancyContainerBox = fancyContainerBox;
        this.fancyMenuBar = fancyMenuBar;
    }

    public override ContainerBox CreateContainerBox() {
        return fancyContainerBox;
    }

    public override MenuBar CreateMenuBar() {
        return fancyMenuBar;
    }
}

Another question is does this pattern encourage code duplication?
Unfortunately, I suspect it does as it's so easy to copy and paste workable code, and so the developer needs to be vigilant and watch out for duplication.

Summary

I have a feeling this is a little bit of an old world pattern as it's a bit unwieldy and maybe there's better and more dynamic ways of constructing complex objects.

References

wiki
Design Patterns [GOF]
dofactory abstract factory pattern
tutorialspoint abstract factory pattern