One of you guys sent me a request to explain the chapter in Refactoring to Patterns titled Encapsulate Composite with Builder. We will build a table structure (composite) using the Builder design pattern.
I’ll expand the capabilities of the code from this great book to allow us to more easily traverse the tree structure. This will allow us to add children, siblings and item information using a HashMap. This is a beautiful refactoring. All of the code can be found below to help you learn it.
If you like videos like this, it helps to tell Google [googleplusone]
Code From the Video
Where is the code ??? =(
Sorry about that. I uploaded it now. I uploaded this very late last night
Very good code, nice way to do a tree with composition using the builder pattern to actually build the tree. Thx a lot!
You’re very welcome 🙂 Many more refactorings are in the works
hey darek,
do you have any plan of making some short video tutorials for how to improve performance of java applications or something like that?
Yes I’ll cover that in the future. For the most part I write pretty code all of the time though
all right
Hello Derek!
Nice tutorial! Had 2 questions on this subject. Would it be good to combine the Builder and Composite pattern in this kind of cases?
What if you try to achieve the same thing, keep track of the tree, with just the Composite pattern (and i guess some “tree-track-holder-class”), is there a reason to choose for the Builder pattern instead?
Always feel free to combine patterns in any way that makes your code easier to understand. There is never a reason to not do something if it makes for understandable code
Hey Derek! Love love the tutorials!
I am trying to make a program that excess a database and using AI changes the data and stores it back.
Would this pattern work well with accessing databases?
Thanks!
Roger
Hey Roger, Thank you very much 🙂 You could use this if you aren’t planning on having a ton of data. A HashMap isn’t very efficient if you have a large number of elements.
Thank you! I appreciate the input!
You’re very welcome 🙂