Giter Club home page Giter Club logo

design-patterns's Introduction

Design-Patterns

Cheetsheets

Factory Pattern

The Factory Pattern - also known as the Factory Method pattern and the Abstract Factory pattern - is typically used when you want to create instances of objects with specific configurations or default values, especially when you have a hierarchy of objects.

You can use the Factory Pattern to create test objects with consistent default values or configurations. It’s useful when you have a complex object creation process, and you want to encapsulate that complexity.

In unit testing, you might use a factory to create mock objects, stubs, or instances of your classes for testing. For instance, you could create a ProductFactory that generates product objects with different categories and prices for testing.

Object Mother Pattern

The Object Mother Pattern is used when you want to create and configure a group of objects with specific attributes or states to be used consistently across multiple test cases. It’s suitable for scenarios where you need predefined test data. The Object Mother pattern does allow for some customizations, through multiple Create options.

Object Mothers are useful for setting up a consistent test environment by providing pre-configured objects or object graphs with various states. This pattern is often used in integration or system testing.

In integration testing, you might use an OrderObjectMother to create order-related objects with specific data (e.g., customers, products, and orders) to simulate various scenarios during testing.

Builder Pattern

The Builder Pattern is used when you need to construct complex objects step by step and provide flexibility in configuring their attributes. It’s particularly useful when there are many optional parameters to set.

This is commonly seen with classes with a large amount of customizable parameters. The Builder class has a private variable to hold the base object. Use With... methods to allow for a specific parameter to be set. The Builder has a Build() method to return the object with all of its customizations.

The Builder Pattern is valuable for creating test objects with customizable attributes. It’s especially useful when you need to set a specific combination of properties for your test objects.

In unit testing, you could use a builder to construct instances of a class with various configurations. For instance, you might have a ProductBuilder that allows you to set different product attributes like name, price, and category during object creation.

design-patterns's People

Contributors

mariyanyordanov avatar

Watchers

 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.