Abstract Factory Pattern
In a earlier blog I explained about Factory pattern. Here Abstract Factory pattern is the the way of encapsulating a group of factories which has same theme.
In a earlier blog I explained about Factory pattern. Here Abstract Factory pattern is the the way of encapsulating a group of factories which has same theme.
When we are working multi threaded environment, diagnosing a problem through a log is not easy task. we can't see one threads execution flow correctly. We can print thread name as an option. then we can grep through that thread name and find the flow. but for that you shuold have asign a proper thread name. But Think this scenario. Many messages are comming to the system and those are processed by a thread pool. we need to find a one message's flow in the log. With NDC.push() we can add message id to every log message. At the end of the flow we can remove that with NDC.pop(). Finaly after thread execution keep in mind to remove all with NDC.remove(). We need to configure log4j.xml with %x to print that pushed value.
Labels: NDC.pop(), NDC.push()
In factory pattern we define an interface to create objects. Concrete class will decide which object need to be created based on parameters passed to the creation method. Withing the factory some times it will maintain an object pool to minimize the cost of creation and initialization of objects. The creation of objects may need some lot of tasks like passing some long parameter list to constructor and setting some required properties via setters. so if we do this object creation every where their will be a massive code duplication. this has a maintainability issues and code readability issues. Some times creation of object may need some resource not appropriate to view in every where.

Labels: Factory Method Design pattern