Giter Club home page Giter Club logo

encapsulate-composite-with-builder's Introduction

Refactoring to Patterns – Encapsulate Composite with Builder

Encapsulate Composite with Builder is the refactoring described in Chapter 6 of the book Refactoring to Patterns.

The commits in this repository try to mimic the test-driven steps described in the example section of the chapter. The first commit represents the initial state with the Composite TagNode.

We report below the mechanics of this refactoring.

Mechanics

The following mechanics assume you already have Composite-construction code and you'd like to encapsulate this code with a Builder.

  1. Create a builder, a new class that will become a Builder (see Design Patterns) by the end of this refactoring. Make it possible for your builder to produce a one-node Composite. Add a method to the builder to obtain the result of its build.

    ✅ Compile and test.

  2. Make the builder capable of building children. This often involves creating multiple methods for allowing clients to easily direct the creation and positioning of children.

    ✅ Compile and test.

  3. If the Composite-construction code you're replacing sets attributes or values on nodes, make the builder capable of settings those attributes and values.

    ✅ Compile and test.

  4. Reflect on how simple your builder is for client to use, and then make it simpler.

    ✅ Compile and test.

  5. Refactor your Composite-construction code to use the new builder. This involves making your client code what is knows in Design Patterns as a Builder:Client and Builder:Director.

    ✅ Compile and test.

encapsulate-composite-with-builder's People

Contributors

dario-campagna avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.