This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hello, Can anyone please tell me what type of Java pattern does log4j follow?
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
posted
0
It's not just one pattern. Design patterns are much more fine in granularity.
Why do you ask?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Nisha Patil
Greenhorn
Joined: May 19, 2008
Posts: 8
posted
0
Hello Ilja, I was asked this question in one of the interviews...could you please tell me if it follows any design pattern(s)
Logger.getLogger(something in here) looks like some sort of builder pattern to me.
Nisha Patil
Greenhorn
Joined: May 19, 2008
Posts: 8
posted
0
Hello David, thanks for the info about the format of name.I've updated my profile.Hope its fine now. I did a google search and found on serverside that the Logger.getLogger(something in here) follows some Aspect pattern.'am not sure what is aspect pattern.
I thing you mean 'aspect oriented', as in Aspect Oriented Programming (AOP) opposed to Object Oriented, although the two aren't incompatible.
Nisha Patil
Greenhorn
Joined: May 19, 2008
Posts: 8
posted
0
I do not know what is aspect pattern.Just read came across it on the website. In one of your previous replies you said "Logger.getLogger(something in here) looks like some sort of builder pattern to me."
I'm just curious to know how its a kinda builder pattern?
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
posted
0
Originally posted by David O'Meara: Logger.getLogger(something in here) looks like some sort of builder pattern to me.
Does it? I don't see it - especially since it's a single static method call. A build typically has a number of method calls on a builder object.
Nisha Patil
Greenhorn
Joined: May 19, 2008
Posts: 8
posted
0
I didnt get any satisfactory answer yet to my query..can anyone please explain to me if the log4j follows any design patterns?
Ilja: I was just trying to have something to say and start conversation
Nisha: It undoubtedly does. I'd have a look at the source and developer notes if I were you.
Nicolas Brasseur
Ranch Hand
Joined: Nov 09, 2001
Posts: 45
posted
0
Hi Nisha,
at first sight I would say Strategy and Factory.
Strategy because using the Log4J getLogger() method hides the real implementation returned. The only thing you know is that it is a subclass of Logger. Kind of Abstract Factory or Factory Method that hides the instantiation of the real object. You don't have to write any new keyword.
For the rest, you should have a look at the internals ...
Nicolas
<a href="http://www.javablackbelt.com/?utm_source=javaranch&utm_medium=signature&utm_campaign=Forum%2BBuzz" target="_blank" rel="nofollow">BlackBeltFactory Communtiy</a> founder - Building better developers<br /><b>Free</b> courses and mock exams
Nicolas Brasseur
Ranch Hand
Joined: Nov 09, 2001
Posts: 45
posted
0
By the way ...
I personally isolate the call to Logger.getLogger(String or Class) in to a static method in a helper class HelperLogger.getLogger() that does not take any argument. In this method I use the Thread.currentThread().getStackTrace() that returns a StackTraceElement array. Using the StackTraceElement.getClassName() I retrieve the String to be passed to the Logger.getLogger(String) of Log4J.
The main advantage is that you can now cut&paste you LoggerHelper.getLogger() statements in all your classes without having to modify them.
Nicolas
[ May 29, 2008: Message edited by: Nicolas Brasseur ] [ May 29, 2008: Message edited by: Nicolas Brasseur ]