
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
474
|
Chapter 8: Diagnostics
public Bar( ) {}
public override void SomeBehavior( )
{
base.SomeBehavior( );
}
}
public class BarTraceInst : Foo
{
public BarTraceInst( )
{
Trace.WriteLine("BarTraceInst object instantiated");
}
public override void SomeBehavior( )
{
base.SomeBehavior( );
}
}
public class BarTraceBehavior : Foo
{
public BarTraceBehavior( ) {}
public override void SomeBehavior( )
{
Trace.WriteLine("SomeBehavior called");
base.SomeBehavior( );
}
}
Discussion
The factory design pattern is designed to abstract away the creation of objects within
a system. This pattern allows code to create objects of a particular type by using an
intermediate object called a factory. In its simplest form, a factory pattern consists of
some client code that uses a factory object to create and return a specific type of
object. The factory pattern allows changes to be made in the way objects are cre-
ated, independent of the client code. This design prevents code changes to the way
an object is constructed from permeating throughout the client code.
Consider that you could have a class that contained numerous lines of tracing code.
If you ran this code to obtain the trace output, you would be inundated with reams
of information. This setup is hard to manage and even harder to read to pinpoint
problems ...