File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Pattern Puzzle!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Pattern Puzzle!!!" Watch "Pattern Puzzle!!!" New topic
Author

Pattern Puzzle!!!

Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
Dear Ranchers,

I got the following puzzle. Can you please have a look at it and care to expand a bit on this?




I have interacted with an interface called Builder
who employs its staff (say masons, labourers, floor fixer, painter etc.)
to get the house constructed for me.

The house after occupying shows a lot of weaknesses in its structure and in the works performed.
What pattern is this first of all?

Now, I have lost my trust on this interface.
What pattern would patch up the weaknesses shown by the above interface?



Your help in this regard is much appreciated.

Cheers,
Ram.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

So, was this an interview question you got, or a class test question that you got?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Whatever it was, I would have had no idea what to answer - and I think I'm rather pattern-literate...


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
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

I would make this face

:roll:

turn, and slowly walk away.


[Jess in Action][AskingGoodQuestions]
Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
Dear All,

The replies were so cool, especially the one by Ernest . This was a question, posed to me , by one of my collegues. We attended a training program on Design Patterns and this is the outcome of the training.

Am trying to find a clue to get the way out

Cheers,
Ram.
B.Sathish
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
This looks like the Builder pattern. In the builder pattern, the client uses a builder interface to construct a product in multiple steps. Thats what is happening here. The builder constructs the house in steps (masons, labourers, floor fixer, painter implement the different steps)

Now for the second part, what pattern should be used to patch up on the weaknesses. Probably the template method pattern. You are not satisfied with the builder because you have no control over the processes employed. With the template method pattern, you can define an algorithm to build a house and specify the steps that you want and then allow the builder subclass to implement certain steps in the algorithm without changing the algorithm's structure. That way you can have control over the building process

Does that make sense?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Nice.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Well, "patching up" could also be interpreted as the Decorator pattern...
[ February 14, 2006: Message edited by: Ilja Preuss ]
C Balajee
Greenhorn

Joined: Oct 18, 2000
Posts: 25
I think the First Pattern is a Builder and the Second is a Decorator.
The Second Cannot be Template Because If the Builder would have Extended the Template then the house would have already been in order.

Nice puzzle..

cheers
Balajee
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I liked Template in the answer because it fits with the centralized control mind-set around here. If there is a problem then we must implement more control, planning, document reviews, checkpoints, etc and delegate to or trust the individual only when we really have to. The base class can enforce the sequence and methodology of steps and impose quality checks on the outputs just like the best micro-manager. Introducing Template where it was not before to "patch up" the situation seems within the rules of the original puzzle.

I'm interested in Decorator, too. How would you decorate a subcontractor? Send somebody along to watch him?

These things don't always translate to The Real World all that well, but this was a rather fun setup.
[ February 17, 2006: Message edited by: Stan James ]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Stan James:

I'm interested in Decorator, too. How would you decorate a subcontractor? Send somebody along to watch him?


Actually I was more thinking about decorating the house - such as hanging pictures over cracks in the wall...
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
That made my day! Thanks!
Raghubir Bose
Ranch Hand

Joined: Feb 18, 2006
Posts: 88
Well , I think that a mediator pattern can be introduced in this situation to make sure that the concretebuilders are executing their buildpart functions properly or not.If the mediator finds that buildpart is not ok then it abandons the build process and calls a penalty object which may be Singleton.

what do you say???


I will meet the fairy queen soon !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pattern Puzzle!!!