Code Monkey home page Code Monkey logo

designpatternsinphp's Introduction

DesignPatternsInPhp

There are lot of excellent resources out there explaining Design Patterns, that is why the goal of this repository is not to listing and explaining them all once again.

Here I want to share different scenarios that helped to understand and apply different design patterns to solve specific problems. So you are going to find:

  • Examples I find in either books or articles that let me understand how to apply a certain pattern. I will refer to the book/article and summarize the problem to solve before going into the pattern design and implementation.
  • Some of my answers in Stackoverflow trying to help others.
  • Real case problems I solved at some point. I am a Domain Driven Design practitioner so many of the Design Patterns listed here come from DDD or helped me to implement this approach.

Patterns

  1. Observer.
  2. Decorator

designpatternsinphp's People

Contributors

mgonzalezbaile avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

designpatternsinphp's Issues

Add Repository pattern

Show how the pattern helps to work with different persistence implementations (Doctrine, MongoDB driver, SQL driver) while keeping the code completely decoupled and contained in the Infrastructure layer.

Aggregate Event Sourcing

Explain ES and share the trait that feeds Aggregate Roots with the capability to apply ES easily.

Add Strategy pattern

Take the first example from the beginning of the book.

Also take the ContractStrategy example.

Add Law Of Demeter

Explain the problems of breaking the law as we make more classes depend on inner classes.
Show how to avoid breaking the law when testing by using Domain Events to test (Booking Request)

Add FixtureBuilder patter

Creating fixture for unit tests gets more complex as long as the code grow. Different shapes of a given class need to be instantiated to test all the different paths in a test.

Show how the FixtureBuilder helps to create, in a readable way, different fixtures of the same class (PaymentOrders)

Add Ports and Adapters (Hexagonal) Architecture

Although not a pattern, an example can be provided to show the benefits of this architecture when working with different adapters (Rest, Soap, Mongo, AMQP, sql) for a given port (Http, Persistence, Messaging).

Add Iterator pattern

Explain how useful is to use this pattern as you forget about how the collection (array, ArrayCollection, Doctrine array,...) making easy for all your clients to use the collection. We have seen the problems of working with arrays when doctrine returns a custom collection which extends IteratorInterface. In this way, even if php in the future adds ArrayCollection or something similar if it implements the common interface we are all safe.

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.