Our Black Friday sale is now live! All individual subscriptions are 50% OFF. This week only!

Back Button Techniques
Open-Closed Workshop

Open-Closed Workshop

In this workshop, we'll focus exclusively on the open-closed principle (the O in SOLID). Using real-life code, line by line, we'll refactor a confusing class into something far more manageable and extendable. Once finished, we'll have gained the luxury of introducing new functionality, not by modifying existing code, but by instead writing a new class.

Advanced
5 episodes
48m
5
Latest Episode in This Series

Added 2 months ago

Discussing Responsibility

As we reach the end of this series, let's take a few moments to discuss responsibility...

Watch
Open-Closed Workshop

Open-Closed Workshop

In this workshop, we'll focus exclusively on the open-closed principle (the O in SOLID). Using real-life code, line by line, we'll refactor a confusing class into something far more manageable and extendable. Once finished, we'll have gained the luxury of introducing new functionality, not by modifying existing code, but by instead writing a new class.

Begin
5
Latest Episode in This Series

Added 2 months ago

Discussing Responsibility

As we reach the end of this series, let's take a few moments to discuss responsibility and...
Watch

Your Teacher | Jeffrey Way

https://laracasts.s3.amazonaws.com/avatars/jeffrey-avatar.jpg's avatar
Hi, I'm Jeffrey. I'm the creator of Laracasts and spend most of my days building the site and thinking of new ways to teach confusing concepts. I live in Orlando, Florida with my wife and two kids.
    1. In order to provide a practical, real-life example of the open-closed principle, we'll use a heavily-modified version of existing code from the Laracasts codebase, itself. This should open up all sorts of refactoring possibilities. Now before we get started, let's first take a few minutes to discuss what we're working with, and where we want to go.

    2. Let's begin our refactoring by applying the squint test. If we squint our eyes and scan the Query, what immediately jumps out at us? Indentation? Common method names? Multiple return types? Let's see!

    3. Let's keep going. In this episode, I'll show you how to remove a conditional by reassigning the "check" to the underlying class.

    4. Let's take the only remaining thing that changes in our Query class, and extract it to a service provider. With this tweak, you'll never have to modify the Query class again. Instead, create a new featured collection, add a new item to your service provider's $collections array, and you're done.

    5. As we reach the end of this series, let's take a few moments to discuss responsibility and awareness. I find that it's useful to frequently ask myself, "Should this class be aware of that particular thing?"