Code Refactoring 11

Code Refactoring 11One 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

13 thoughts on “Code Refactoring 11”

  1. 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?

  2. 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?

    1. 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

  3. 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

    1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *